1d81734caSHemant Agrawal /* SPDX-License-Identifier: BSD-3-Clause 2c3e85bdcSAkhil Goyal * 3c3e85bdcSAkhil Goyal * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved. 4c9fd1acdSGagandeep Singh * Copyright 2017-2024 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> 15af668035SAkhil Goyal #include <cryptodev_pmd.h> 16c3e85bdcSAkhil Goyal #include <rte_crypto.h> 17c3e85bdcSAkhil Goyal #include <rte_cryptodev.h> 181f14d500SAkhil Goyal #include <rte_security_driver.h> 19c3e85bdcSAkhil Goyal #include <rte_cycles.h> 201acb7f54SDavid Marchand #include <dev_driver.h> 218a3167dbSGagandeep Singh #include <rte_io.h> 22bd063651SFerruh Yigit #include <rte_ip.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> 29b1bbf222SGagandeep Singh #include <rte_hexdump.h> 30c3e85bdcSAkhil Goyal 31c3e85bdcSAkhil Goyal #include <fsl_usd.h> 32c3e85bdcSAkhil Goyal #include <fsl_qman.h> 338c83f28cSHemant Agrawal #include <dpaa_of.h> 34c3e85bdcSAkhil Goyal 35c3e85bdcSAkhil Goyal /* RTA header files */ 36c0ded849SHemant Agrawal #include <desc/common.h> 37c0ded849SHemant Agrawal #include <desc/algo.h> 38c0ded849SHemant Agrawal #include <desc/ipsec.h> 39c0ded849SHemant Agrawal #include <desc/pdcp.h> 405a4954bcSAkhil Goyal #include <desc/sdap.h> 41c3e85bdcSAkhil Goyal 42a2f1da7dSDavid Marchand #include <bus_dpaa_driver.h> 43c3e85bdcSAkhil Goyal #include <dpaa_sec.h> 44fe3688baSAkhil Goyal #include <dpaa_sec_event.h> 45c3e85bdcSAkhil Goyal #include <dpaa_sec_log.h> 4612e58429SThierry Herbelot #include <dpaax_iova_table.h> 47c3e85bdcSAkhil Goyal 48b1bbf222SGagandeep Singh #define DRIVER_DUMP_MODE "drv_dump_mode" 49b1bbf222SGagandeep Singh 50b1bbf222SGagandeep Singh /* DPAA_SEC_DP_DUMP levels */ 51b1bbf222SGagandeep Singh enum dpaa_sec_dump_levels { 52b1bbf222SGagandeep Singh DPAA_SEC_DP_NO_DUMP, 53b1bbf222SGagandeep Singh DPAA_SEC_DP_ERR_DUMP, 54b1bbf222SGagandeep Singh DPAA_SEC_DP_FULL_DUMP 55b1bbf222SGagandeep Singh }; 56b1bbf222SGagandeep Singh 57b1bbf222SGagandeep Singh uint8_t dpaa_sec_dp_dump = DPAA_SEC_DP_ERR_DUMP; 58b1bbf222SGagandeep Singh 599d5f73c2SGagandeep Singh uint8_t dpaa_cryptodev_driver_id; 60e79416d1SHemant Agrawal 61c3e85bdcSAkhil Goyal static inline void 62c3e85bdcSAkhil Goyal dpaa_sec_op_ending(struct dpaa_sec_op_ctx *ctx) 63c3e85bdcSAkhil Goyal { 64c3e85bdcSAkhil Goyal if (!ctx->fd_status) { 65c3e85bdcSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 66c3e85bdcSAkhil Goyal } else { 67f163231eSHemant Agrawal DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status); 68c3e85bdcSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR; 69c3e85bdcSAkhil Goyal } 70c3e85bdcSAkhil Goyal } 71c3e85bdcSAkhil Goyal 72c3e85bdcSAkhil Goyal static inline struct dpaa_sec_op_ctx * 73f7a5752eSHemant Agrawal dpaa_sec_alloc_ctx(dpaa_sec_session *ses, int sg_count) 74c3e85bdcSAkhil Goyal { 75c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 76f7a5752eSHemant Agrawal int i, retval; 77c3e85bdcSAkhil Goyal 782ffb940eSAkhil Goyal retval = rte_mempool_get( 792ffb940eSAkhil Goyal ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool, 802ffb940eSAkhil Goyal (void **)(&ctx)); 81c3e85bdcSAkhil Goyal if (!ctx || retval) { 82f163231eSHemant Agrawal DPAA_SEC_DP_WARN("Alloc sec descriptor failed!"); 83c3e85bdcSAkhil Goyal return NULL; 84c3e85bdcSAkhil Goyal } 85c3e85bdcSAkhil Goyal /* 86c3e85bdcSAkhil Goyal * Clear SG memory. There are 16 SG entries of 16 Bytes each. 87c3e85bdcSAkhil Goyal * one call to dcbz_64() clear 64 bytes, hence calling it 4 times 88c3e85bdcSAkhil Goyal * to clear all the SG entries. dpaa_sec_alloc_ctx() is called for 89c3e85bdcSAkhil Goyal * each packet, memset is costlier than dcbz_64(). 90c3e85bdcSAkhil Goyal */ 91f7a5752eSHemant Agrawal for (i = 0; i < sg_count && i < MAX_JOB_SG_ENTRIES; i += 4) 92f7a5752eSHemant Agrawal dcbz_64(&ctx->job.sg[i]); 93c3e85bdcSAkhil Goyal 942ffb940eSAkhil Goyal ctx->ctx_pool = ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool; 95f7a5752eSHemant Agrawal ctx->vtop_offset = (size_t) ctx - rte_mempool_virt2iova(ctx); 96c3e85bdcSAkhil Goyal 97c3e85bdcSAkhil Goyal return ctx; 98c3e85bdcSAkhil Goyal } 99c3e85bdcSAkhil Goyal 100c3e85bdcSAkhil Goyal static void 101c3e85bdcSAkhil Goyal ern_sec_fq_handler(struct qman_portal *qm __rte_unused, 102c3e85bdcSAkhil Goyal struct qman_fq *fq, 103c3e85bdcSAkhil Goyal const struct qm_mr_entry *msg) 104c3e85bdcSAkhil Goyal { 105*f665790aSDavid Marchand DPAA_SEC_DP_ERR("sec fq %d error, RC = %x, seqnum = %x", 106c3e85bdcSAkhil Goyal fq->fqid, msg->ern.rc, msg->ern.seqnum); 107c3e85bdcSAkhil Goyal } 108c3e85bdcSAkhil Goyal 109c3e85bdcSAkhil Goyal /* initialize the queue with dest chan as caam chan so that 110c3e85bdcSAkhil Goyal * all the packets in this queue could be dispatched into caam 111c3e85bdcSAkhil Goyal */ 112c3e85bdcSAkhil Goyal static int 113c4509373SSantosh Shukla dpaa_sec_init_rx(struct qman_fq *fq_in, rte_iova_t hwdesc, 114c3e85bdcSAkhil Goyal uint32_t fqid_out) 115c3e85bdcSAkhil Goyal { 116c3e85bdcSAkhil Goyal struct qm_mcc_initfq fq_opts; 117c3e85bdcSAkhil Goyal uint32_t flags; 118c3e85bdcSAkhil Goyal int ret = -1; 119c3e85bdcSAkhil Goyal 120c3e85bdcSAkhil Goyal /* Clear FQ options */ 121c3e85bdcSAkhil Goyal memset(&fq_opts, 0x00, sizeof(struct qm_mcc_initfq)); 122c3e85bdcSAkhil Goyal 123c3e85bdcSAkhil Goyal flags = QMAN_INITFQ_FLAG_SCHED; 124c3e85bdcSAkhil Goyal fq_opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_CONTEXTA | 125c3e85bdcSAkhil Goyal QM_INITFQ_WE_CONTEXTB; 126c3e85bdcSAkhil Goyal 127c3e85bdcSAkhil Goyal qm_fqd_context_a_set64(&fq_opts.fqd, hwdesc); 128c3e85bdcSAkhil Goyal fq_opts.fqd.context_b = fqid_out; 129a8ee206aSHemant Agrawal fq_opts.fqd.dest.channel = dpaa_get_qm_channel_caam(); 130c3e85bdcSAkhil Goyal fq_opts.fqd.dest.wq = 0; 131c3e85bdcSAkhil Goyal 132c3e85bdcSAkhil Goyal fq_in->cb.ern = ern_sec_fq_handler; 133c3e85bdcSAkhil Goyal 134f163231eSHemant Agrawal DPAA_SEC_DEBUG("in-%x out-%x", fq_in->fqid, fqid_out); 135e79416d1SHemant Agrawal 136c3e85bdcSAkhil Goyal ret = qman_init_fq(fq_in, flags, &fq_opts); 137c3e85bdcSAkhil Goyal if (unlikely(ret != 0)) 138f163231eSHemant Agrawal DPAA_SEC_ERR("qman_init_fq failed %d", ret); 139c3e85bdcSAkhil Goyal 140c3e85bdcSAkhil Goyal return ret; 141c3e85bdcSAkhil Goyal } 142c3e85bdcSAkhil Goyal 143c3e85bdcSAkhil Goyal /* something is put into in_fq and caam put the crypto result into out_fq */ 144c3e85bdcSAkhil Goyal static enum qman_cb_dqrr_result 145c3e85bdcSAkhil Goyal dqrr_out_fq_cb_rx(struct qman_portal *qm __always_unused, 146c3e85bdcSAkhil Goyal struct qman_fq *fq __always_unused, 147c3e85bdcSAkhil Goyal const struct qm_dqrr_entry *dqrr) 148c3e85bdcSAkhil Goyal { 149c3e85bdcSAkhil Goyal const struct qm_fd *fd; 150c3e85bdcSAkhil Goyal struct dpaa_sec_job *job; 151c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 152c3e85bdcSAkhil Goyal 153c3e85bdcSAkhil Goyal if (!(dqrr->stat & QM_DQRR_STAT_FD_VALID)) 154c3e85bdcSAkhil Goyal return qman_cb_dqrr_consume; 155c3e85bdcSAkhil Goyal 156c3e85bdcSAkhil Goyal fd = &dqrr->fd; 157c3e85bdcSAkhil Goyal /* sg is embedded in an op ctx, 158c3e85bdcSAkhil Goyal * sg[0] is for output 159c3e85bdcSAkhil Goyal * sg[1] for input 160c3e85bdcSAkhil Goyal */ 161ec861560SGagandeep Singh job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd)); 1621f14d500SAkhil Goyal 163c3e85bdcSAkhil Goyal ctx = container_of(job, struct dpaa_sec_op_ctx, job); 164c3e85bdcSAkhil Goyal ctx->fd_status = fd->status; 1651f14d500SAkhil Goyal if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) { 1661f14d500SAkhil Goyal struct qm_sg_entry *sg_out; 1671f14d500SAkhil Goyal uint32_t len; 168fb5c100aSAkhil Goyal struct rte_mbuf *mbuf = (ctx->op->sym->m_dst == NULL) ? 169fb5c100aSAkhil Goyal ctx->op->sym->m_src : ctx->op->sym->m_dst; 1701f14d500SAkhil Goyal 1711f14d500SAkhil Goyal sg_out = &job->sg[0]; 1721f14d500SAkhil Goyal hw_sg_to_cpu(sg_out); 1731f14d500SAkhil Goyal len = sg_out->length; 174fb5c100aSAkhil Goyal mbuf->pkt_len = len; 175fb5c100aSAkhil Goyal while (mbuf->next != NULL) { 176fb5c100aSAkhil Goyal len -= mbuf->data_len; 177fb5c100aSAkhil Goyal mbuf = mbuf->next; 178fb5c100aSAkhil Goyal } 179fb5c100aSAkhil Goyal mbuf->data_len = len; 1801f14d500SAkhil Goyal } 181c3e85bdcSAkhil Goyal dpaa_sec_op_ending(ctx); 182c3e85bdcSAkhil Goyal 183c3e85bdcSAkhil Goyal return qman_cb_dqrr_consume; 184c3e85bdcSAkhil Goyal } 185c3e85bdcSAkhil Goyal 186c3e85bdcSAkhil Goyal /* caam result is put into this queue */ 187c3e85bdcSAkhil Goyal static int 188c3e85bdcSAkhil Goyal dpaa_sec_init_tx(struct qman_fq *fq) 189c3e85bdcSAkhil Goyal { 190c3e85bdcSAkhil Goyal int ret; 191c3e85bdcSAkhil Goyal struct qm_mcc_initfq opts; 192c3e85bdcSAkhil Goyal uint32_t flags; 193c3e85bdcSAkhil Goyal 194c3e85bdcSAkhil Goyal flags = QMAN_FQ_FLAG_NO_ENQUEUE | QMAN_FQ_FLAG_LOCKED | 195c3e85bdcSAkhil Goyal QMAN_FQ_FLAG_DYNAMIC_FQID; 196c3e85bdcSAkhil Goyal 197c3e85bdcSAkhil Goyal ret = qman_create_fq(0, flags, fq); 198c3e85bdcSAkhil Goyal if (unlikely(ret)) { 199f163231eSHemant Agrawal DPAA_SEC_ERR("qman_create_fq failed"); 200c3e85bdcSAkhil Goyal return ret; 201c3e85bdcSAkhil Goyal } 202c3e85bdcSAkhil Goyal 203c3e85bdcSAkhil Goyal memset(&opts, 0, sizeof(opts)); 204c3e85bdcSAkhil Goyal opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL | 205c3e85bdcSAkhil Goyal QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB; 206c3e85bdcSAkhil Goyal 207c3e85bdcSAkhil Goyal /* opts.fqd.dest.channel = dpaa_sec_pool_chan; */ 208c3e85bdcSAkhil Goyal 209c3e85bdcSAkhil Goyal fq->cb.dqrr = dqrr_out_fq_cb_rx; 210c3e85bdcSAkhil Goyal fq->cb.ern = ern_sec_fq_handler; 211c3e85bdcSAkhil Goyal 212c3e85bdcSAkhil Goyal ret = qman_init_fq(fq, 0, &opts); 213c3e85bdcSAkhil Goyal if (unlikely(ret)) { 214f163231eSHemant Agrawal DPAA_SEC_ERR("unable to init caam source fq!"); 215c3e85bdcSAkhil Goyal return ret; 216c3e85bdcSAkhil Goyal } 217c3e85bdcSAkhil Goyal 218c3e85bdcSAkhil Goyal return ret; 219c3e85bdcSAkhil Goyal } 220c3e85bdcSAkhil Goyal 2216290de2cSLukasz Wojciechowski static inline int is_aead(dpaa_sec_session *ses) 2226290de2cSLukasz Wojciechowski { 2236290de2cSLukasz Wojciechowski return ((ses->cipher_alg == 0) && 2246290de2cSLukasz Wojciechowski (ses->auth_alg == 0) && 2256290de2cSLukasz Wojciechowski (ses->aead_alg != 0)); 2266290de2cSLukasz Wojciechowski } 2276290de2cSLukasz Wojciechowski 228c3e85bdcSAkhil Goyal static inline int is_encode(dpaa_sec_session *ses) 229c3e85bdcSAkhil Goyal { 230c3e85bdcSAkhil Goyal return ses->dir == DIR_ENC; 231c3e85bdcSAkhil Goyal } 232c3e85bdcSAkhil Goyal 233c3e85bdcSAkhil Goyal static inline int is_decode(dpaa_sec_session *ses) 234c3e85bdcSAkhil Goyal { 235c3e85bdcSAkhil Goyal return ses->dir == DIR_DEC; 236c3e85bdcSAkhil Goyal } 237c3e85bdcSAkhil Goyal 238a1173d55SHemant Agrawal static int 239a1173d55SHemant Agrawal dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses) 240a1173d55SHemant Agrawal { 241a1173d55SHemant Agrawal struct alginfo authdata = {0}, cipherdata = {0}; 242a1173d55SHemant Agrawal struct sec_cdb *cdb = &ses->cdb; 2432e4cbdb4SVakul Garg struct alginfo *p_authdata = NULL; 244a1173d55SHemant Agrawal int32_t shared_desc_len = 0; 245a1173d55SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 246a1173d55SHemant Agrawal int swap = false; 247a1173d55SHemant Agrawal #else 248a1173d55SHemant Agrawal int swap = true; 249a1173d55SHemant Agrawal #endif 250a1173d55SHemant Agrawal 251a1173d55SHemant Agrawal cipherdata.key = (size_t)ses->cipher_key.data; 252a1173d55SHemant Agrawal cipherdata.keylen = ses->cipher_key.length; 253a1173d55SHemant Agrawal cipherdata.key_enc_flags = 0; 254a1173d55SHemant Agrawal cipherdata.key_type = RTA_DATA_IMM; 2558524b44eSHemant Agrawal cipherdata.algtype = ses->cipher_key.alg; 2568524b44eSHemant Agrawal cipherdata.algmode = ses->cipher_key.algmode; 257a1173d55SHemant Agrawal 2582e4cbdb4SVakul Garg if (ses->auth_alg) { 259a1173d55SHemant Agrawal authdata.key = (size_t)ses->auth_key.data; 260a1173d55SHemant Agrawal authdata.keylen = ses->auth_key.length; 261a1173d55SHemant Agrawal authdata.key_enc_flags = 0; 262a1173d55SHemant Agrawal authdata.key_type = RTA_DATA_IMM; 2638524b44eSHemant Agrawal authdata.algtype = ses->auth_key.alg; 2648524b44eSHemant Agrawal authdata.algmode = ses->auth_key.algmode; 265a1173d55SHemant Agrawal 2662e4cbdb4SVakul Garg p_authdata = &authdata; 2672e4cbdb4SVakul Garg } 2682e4cbdb4SVakul Garg 269ebc27d1bSFranck Lenormand if (ses->pdcp.sdap_enabled) { 270ebc27d1bSFranck Lenormand int nb_keys_to_inline = 271ebc27d1bSFranck Lenormand rta_inline_pdcp_sdap_query(authdata.algtype, 272ebc27d1bSFranck Lenormand cipherdata.algtype, 273ebc27d1bSFranck Lenormand ses->pdcp.sn_size, 274ebc27d1bSFranck Lenormand ses->pdcp.hfn_ovd); 275ebc27d1bSFranck Lenormand if (nb_keys_to_inline >= 1) { 276ebc27d1bSFranck Lenormand cipherdata.key = (size_t)rte_dpaa_mem_vtop((void *) 277ebc27d1bSFranck Lenormand (size_t)cipherdata.key); 278ebc27d1bSFranck Lenormand cipherdata.key_type = RTA_DATA_PTR; 279ebc27d1bSFranck Lenormand } 280ebc27d1bSFranck Lenormand if (nb_keys_to_inline >= 2) { 281ebc27d1bSFranck Lenormand authdata.key = (size_t)rte_dpaa_mem_vtop((void *) 282ebc27d1bSFranck Lenormand (size_t)authdata.key); 283ebc27d1bSFranck Lenormand authdata.key_type = RTA_DATA_PTR; 284ebc27d1bSFranck Lenormand } 285ebc27d1bSFranck Lenormand } else { 286f6ab96f1SAkhil Goyal if (rta_inline_pdcp_query(authdata.algtype, 287f6ab96f1SAkhil Goyal cipherdata.algtype, 288f6ab96f1SAkhil Goyal ses->pdcp.sn_size, 289f6ab96f1SAkhil Goyal ses->pdcp.hfn_ovd)) { 290ebc27d1bSFranck Lenormand cipherdata.key = (size_t)rte_dpaa_mem_vtop((void *) 291f6ab96f1SAkhil Goyal (size_t)cipherdata.key); 292a1173d55SHemant Agrawal cipherdata.key_type = RTA_DATA_PTR; 293a1173d55SHemant Agrawal } 294ebc27d1bSFranck Lenormand } 295a1173d55SHemant Agrawal 2962e4cbdb4SVakul Garg if (ses->pdcp.domain == RTE_SECURITY_PDCP_MODE_CONTROL) { 297a1173d55SHemant Agrawal if (ses->dir == DIR_ENC) 298a1173d55SHemant Agrawal shared_desc_len = cnstr_shdsc_pdcp_c_plane_encap( 299a1173d55SHemant Agrawal cdb->sh_desc, 1, swap, 300a1173d55SHemant Agrawal ses->pdcp.hfn, 301eac60082SVakul Garg ses->pdcp.sn_size, 302a1173d55SHemant Agrawal ses->pdcp.bearer, 303a1173d55SHemant Agrawal ses->pdcp.pkt_dir, 304a1173d55SHemant Agrawal ses->pdcp.hfn_threshold, 3056127fff8SFranck Lenormand &cipherdata, &authdata); 306a1173d55SHemant Agrawal else if (ses->dir == DIR_DEC) 307a1173d55SHemant Agrawal shared_desc_len = cnstr_shdsc_pdcp_c_plane_decap( 308a1173d55SHemant Agrawal cdb->sh_desc, 1, swap, 309a1173d55SHemant Agrawal ses->pdcp.hfn, 310eac60082SVakul Garg ses->pdcp.sn_size, 311a1173d55SHemant Agrawal ses->pdcp.bearer, 312a1173d55SHemant Agrawal ses->pdcp.pkt_dir, 313a1173d55SHemant Agrawal ses->pdcp.hfn_threshold, 3146127fff8SFranck Lenormand &cipherdata, &authdata); 31593e2661eSGagandeep Singh } else if (ses->pdcp.domain == RTE_SECURITY_PDCP_MODE_SHORT_MAC) { 31693e2661eSGagandeep Singh shared_desc_len = cnstr_shdsc_pdcp_short_mac(cdb->sh_desc, 31793e2661eSGagandeep Singh 1, swap, &authdata); 318a1173d55SHemant Agrawal } else { 3195a4954bcSAkhil Goyal if (ses->dir == DIR_ENC) { 3205a4954bcSAkhil Goyal if (ses->pdcp.sdap_enabled) 3215a4954bcSAkhil Goyal shared_desc_len = 3225a4954bcSAkhil Goyal cnstr_shdsc_pdcp_sdap_u_plane_encap( 323a1173d55SHemant Agrawal cdb->sh_desc, 1, swap, 324a1173d55SHemant Agrawal ses->pdcp.sn_size, 325a1173d55SHemant Agrawal ses->pdcp.hfn, 326a1173d55SHemant Agrawal ses->pdcp.bearer, 327a1173d55SHemant Agrawal ses->pdcp.pkt_dir, 328a1173d55SHemant Agrawal ses->pdcp.hfn_threshold, 3296127fff8SFranck Lenormand &cipherdata, p_authdata); 3305a4954bcSAkhil Goyal else 3315a4954bcSAkhil Goyal shared_desc_len = 3325a4954bcSAkhil Goyal cnstr_shdsc_pdcp_u_plane_encap( 333a1173d55SHemant Agrawal cdb->sh_desc, 1, swap, 334a1173d55SHemant Agrawal ses->pdcp.sn_size, 335a1173d55SHemant Agrawal ses->pdcp.hfn, 336a1173d55SHemant Agrawal ses->pdcp.bearer, 337a1173d55SHemant Agrawal ses->pdcp.pkt_dir, 338a1173d55SHemant Agrawal ses->pdcp.hfn_threshold, 3396127fff8SFranck Lenormand &cipherdata, p_authdata); 3405a4954bcSAkhil Goyal } else if (ses->dir == DIR_DEC) { 3415a4954bcSAkhil Goyal if (ses->pdcp.sdap_enabled) 3425a4954bcSAkhil Goyal shared_desc_len = 3435a4954bcSAkhil Goyal cnstr_shdsc_pdcp_sdap_u_plane_decap( 3445a4954bcSAkhil Goyal cdb->sh_desc, 1, swap, 3455a4954bcSAkhil Goyal ses->pdcp.sn_size, 3465a4954bcSAkhil Goyal ses->pdcp.hfn, 3475a4954bcSAkhil Goyal ses->pdcp.bearer, 3485a4954bcSAkhil Goyal ses->pdcp.pkt_dir, 3495a4954bcSAkhil Goyal ses->pdcp.hfn_threshold, 3506127fff8SFranck Lenormand &cipherdata, p_authdata); 3515a4954bcSAkhil Goyal else 3525a4954bcSAkhil Goyal shared_desc_len = 3535a4954bcSAkhil Goyal cnstr_shdsc_pdcp_u_plane_decap( 3545a4954bcSAkhil Goyal cdb->sh_desc, 1, swap, 3555a4954bcSAkhil Goyal ses->pdcp.sn_size, 3565a4954bcSAkhil Goyal ses->pdcp.hfn, 3575a4954bcSAkhil Goyal ses->pdcp.bearer, 3585a4954bcSAkhil Goyal ses->pdcp.pkt_dir, 3595a4954bcSAkhil Goyal ses->pdcp.hfn_threshold, 3606127fff8SFranck Lenormand &cipherdata, p_authdata); 3615a4954bcSAkhil Goyal } 362a1173d55SHemant Agrawal } 363a1173d55SHemant Agrawal return shared_desc_len; 364a1173d55SHemant Agrawal } 365a1173d55SHemant Agrawal 36605b12700SHemant Agrawal /* prepare ipsec proto command block of the session */ 36705b12700SHemant Agrawal static int 36805b12700SHemant Agrawal dpaa_sec_prep_ipsec_cdb(dpaa_sec_session *ses) 36905b12700SHemant Agrawal { 37005b12700SHemant Agrawal struct alginfo cipherdata = {0}, authdata = {0}; 37105b12700SHemant Agrawal struct sec_cdb *cdb = &ses->cdb; 37205b12700SHemant Agrawal int32_t shared_desc_len = 0; 37305b12700SHemant Agrawal int err; 37405b12700SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 37505b12700SHemant Agrawal int swap = false; 37605b12700SHemant Agrawal #else 37705b12700SHemant Agrawal int swap = true; 37805b12700SHemant Agrawal #endif 37905b12700SHemant Agrawal 38005b12700SHemant Agrawal cipherdata.key = (size_t)ses->cipher_key.data; 38105b12700SHemant Agrawal cipherdata.keylen = ses->cipher_key.length; 38205b12700SHemant Agrawal cipherdata.key_enc_flags = 0; 38305b12700SHemant Agrawal cipherdata.key_type = RTA_DATA_IMM; 3848524b44eSHemant Agrawal cipherdata.algtype = ses->cipher_key.alg; 3858524b44eSHemant Agrawal cipherdata.algmode = ses->cipher_key.algmode; 38605b12700SHemant Agrawal 3872c318722SHemant Agrawal if (ses->auth_key.length) { 38805b12700SHemant Agrawal authdata.key = (size_t)ses->auth_key.data; 38905b12700SHemant Agrawal authdata.keylen = ses->auth_key.length; 39005b12700SHemant Agrawal authdata.key_enc_flags = 0; 39105b12700SHemant Agrawal authdata.key_type = RTA_DATA_IMM; 3928524b44eSHemant Agrawal authdata.algtype = ses->auth_key.alg; 3938524b44eSHemant Agrawal authdata.algmode = ses->auth_key.algmode; 3942c318722SHemant Agrawal } 39505b12700SHemant Agrawal 39605b12700SHemant Agrawal cdb->sh_desc[0] = cipherdata.keylen; 39705b12700SHemant Agrawal cdb->sh_desc[1] = authdata.keylen; 39804634157SGagandeep Singh err = rta_inline_ipsec_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN, 399453b9593SAkhil Goyal DESC_JOB_IO_LEN, 40005b12700SHemant Agrawal (unsigned int *)cdb->sh_desc, 40104634157SGagandeep Singh &cdb->sh_desc[2], 2, authdata.algtype, 1); 40205b12700SHemant Agrawal 40305b12700SHemant Agrawal if (err < 0) { 40405b12700SHemant Agrawal DPAA_SEC_ERR("Crypto: Incorrect key lengths"); 40505b12700SHemant Agrawal return err; 40605b12700SHemant Agrawal } 40705b12700SHemant Agrawal if (cdb->sh_desc[2] & 1) 40805b12700SHemant Agrawal cipherdata.key_type = RTA_DATA_IMM; 40905b12700SHemant Agrawal else { 410ec861560SGagandeep Singh cipherdata.key = (size_t)rte_dpaa_mem_vtop( 41105b12700SHemant Agrawal (void *)(size_t)cipherdata.key); 41205b12700SHemant Agrawal cipherdata.key_type = RTA_DATA_PTR; 41305b12700SHemant Agrawal } 41405b12700SHemant Agrawal if (cdb->sh_desc[2] & (1<<1)) 41505b12700SHemant Agrawal authdata.key_type = RTA_DATA_IMM; 41605b12700SHemant Agrawal else { 417ec861560SGagandeep Singh authdata.key = (size_t)rte_dpaa_mem_vtop( 41805b12700SHemant Agrawal (void *)(size_t)authdata.key); 41905b12700SHemant Agrawal authdata.key_type = RTA_DATA_PTR; 42005b12700SHemant Agrawal } 42105b12700SHemant Agrawal 42205b12700SHemant Agrawal cdb->sh_desc[0] = 0; 42305b12700SHemant Agrawal cdb->sh_desc[1] = 0; 42405b12700SHemant Agrawal cdb->sh_desc[2] = 0; 42505b12700SHemant Agrawal if (ses->dir == DIR_ENC) { 42605b12700SHemant Agrawal shared_desc_len = cnstr_shdsc_ipsec_new_encap( 42705b12700SHemant Agrawal cdb->sh_desc, 42805b12700SHemant Agrawal true, swap, SHR_SERIAL, 42905b12700SHemant Agrawal &ses->encap_pdb, 43005b12700SHemant Agrawal (uint8_t *)&ses->ip4_hdr, 43105b12700SHemant Agrawal &cipherdata, &authdata); 43205b12700SHemant Agrawal } else if (ses->dir == DIR_DEC) { 43305b12700SHemant Agrawal shared_desc_len = cnstr_shdsc_ipsec_new_decap( 43405b12700SHemant Agrawal cdb->sh_desc, 43505b12700SHemant Agrawal true, swap, SHR_SERIAL, 43605b12700SHemant Agrawal &ses->decap_pdb, 43705b12700SHemant Agrawal &cipherdata, &authdata); 43805b12700SHemant Agrawal } 43905b12700SHemant Agrawal return shared_desc_len; 44005b12700SHemant Agrawal } 44176c129ceSMaxime Coquelin 442c3e85bdcSAkhil Goyal /* prepare command block of the session */ 443c3e85bdcSAkhil Goyal static int 444c3e85bdcSAkhil Goyal dpaa_sec_prep_cdb(dpaa_sec_session *ses) 445c3e85bdcSAkhil Goyal { 446c3e85bdcSAkhil Goyal struct alginfo alginfo_c = {0}, alginfo_a = {0}, alginfo = {0}; 44722788c2cSSunil Kumar Kori int32_t shared_desc_len = 0; 448e79416d1SHemant Agrawal struct sec_cdb *cdb = &ses->cdb; 449c3e85bdcSAkhil Goyal int err; 450c3e85bdcSAkhil Goyal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 451c3e85bdcSAkhil Goyal int swap = false; 452c3e85bdcSAkhil Goyal #else 453c3e85bdcSAkhil Goyal int swap = true; 454c3e85bdcSAkhil Goyal #endif 455c3e85bdcSAkhil Goyal 456c3e85bdcSAkhil Goyal memset(cdb, 0, sizeof(struct sec_cdb)); 457c3e85bdcSAkhil Goyal 4588524b44eSHemant Agrawal switch (ses->ctxt) { 4598524b44eSHemant Agrawal case DPAA_SEC_IPSEC: 46005b12700SHemant Agrawal shared_desc_len = dpaa_sec_prep_ipsec_cdb(ses); 4618524b44eSHemant Agrawal break; 4628524b44eSHemant Agrawal case DPAA_SEC_PDCP: 463a1173d55SHemant Agrawal shared_desc_len = dpaa_sec_prep_pdcp_cdb(ses); 4648524b44eSHemant Agrawal break; 4658524b44eSHemant Agrawal case DPAA_SEC_CIPHER: 4660e5607e4SHemant Agrawal alginfo_c.key = (size_t)ses->cipher_key.data; 467c3e85bdcSAkhil Goyal alginfo_c.keylen = ses->cipher_key.length; 468c3e85bdcSAkhil Goyal alginfo_c.key_enc_flags = 0; 469c3e85bdcSAkhil Goyal alginfo_c.key_type = RTA_DATA_IMM; 4708524b44eSHemant Agrawal alginfo_c.algtype = ses->cipher_key.alg; 4718524b44eSHemant Agrawal alginfo_c.algmode = ses->cipher_key.algmode; 4728524b44eSHemant Agrawal 473c5788a10SHemant Agrawal switch (ses->cipher_alg) { 474c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CBC: 475c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_3DES_CBC: 4763e4fbc6cSGagandeep Singh case RTE_CRYPTO_CIPHER_DES_CBC: 477c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CTR: 478c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_3DES_CTR: 479c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_blkcipher( 480c5788a10SHemant Agrawal cdb->sh_desc, true, 481c5788a10SHemant Agrawal swap, SHR_NEVER, &alginfo_c, 482c5788a10SHemant Agrawal ses->iv.length, 483c5788a10SHemant Agrawal ses->dir); 484c5788a10SHemant Agrawal break; 485c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: 486c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_snow_f8( 487c5788a10SHemant Agrawal cdb->sh_desc, true, swap, 488c5788a10SHemant Agrawal &alginfo_c, 489c5788a10SHemant Agrawal ses->dir); 490c5788a10SHemant Agrawal break; 491c5788a10SHemant Agrawal case RTE_CRYPTO_CIPHER_ZUC_EEA3: 492c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_zuce( 493c5788a10SHemant Agrawal cdb->sh_desc, true, swap, 494c5788a10SHemant Agrawal &alginfo_c, 495c5788a10SHemant Agrawal ses->dir); 496c5788a10SHemant Agrawal break; 497c5788a10SHemant Agrawal default: 49877a9b5adSHemant Agrawal DPAA_SEC_ERR("unsupported cipher alg %s (%d)", 49977a9b5adSHemant Agrawal rte_cryptodev_get_cipher_algo_string(ses->cipher_alg), 500c5788a10SHemant Agrawal ses->cipher_alg); 501c3e85bdcSAkhil Goyal return -ENOTSUP; 502c3e85bdcSAkhil Goyal } 5038524b44eSHemant Agrawal break; 5048524b44eSHemant Agrawal case DPAA_SEC_AUTH: 5050e5607e4SHemant Agrawal alginfo_a.key = (size_t)ses->auth_key.data; 506c3e85bdcSAkhil Goyal alginfo_a.keylen = ses->auth_key.length; 507c3e85bdcSAkhil Goyal alginfo_a.key_enc_flags = 0; 508c3e85bdcSAkhil Goyal alginfo_a.key_type = RTA_DATA_IMM; 5098524b44eSHemant Agrawal alginfo_a.algtype = ses->auth_key.alg; 5108524b44eSHemant Agrawal alginfo_a.algmode = ses->auth_key.algmode; 511c5788a10SHemant Agrawal switch (ses->auth_alg) { 5124c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_MD5: 5134c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA1: 5144c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA224: 5154c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA256: 5164c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA384: 5174c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA512: 5184c42352cSGagandeep Singh shared_desc_len = cnstr_shdsc_hash( 5194c42352cSGagandeep Singh cdb->sh_desc, true, 5204c42352cSGagandeep Singh swap, SHR_NEVER, &alginfo_a, 5214c42352cSGagandeep Singh !ses->dir, 5224c42352cSGagandeep Singh ses->digest_length); 5234c42352cSGagandeep Singh break; 524c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_MD5_HMAC: 525c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SHA1_HMAC: 526c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SHA224_HMAC: 527c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SHA256_HMAC: 528c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SHA384_HMAC: 529c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SHA512_HMAC: 530c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_hmac( 531c5788a10SHemant Agrawal cdb->sh_desc, true, 532c5788a10SHemant Agrawal swap, SHR_NEVER, &alginfo_a, 533c5788a10SHemant Agrawal !ses->dir, 534c5788a10SHemant Agrawal ses->digest_length); 535c5788a10SHemant Agrawal break; 536c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_SNOW3G_UIA2: 537c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_snow_f9( 538c5788a10SHemant Agrawal cdb->sh_desc, true, swap, 539c5788a10SHemant Agrawal &alginfo_a, 540c5788a10SHemant Agrawal !ses->dir, 541c5788a10SHemant Agrawal ses->digest_length); 542c5788a10SHemant Agrawal break; 543c5788a10SHemant Agrawal case RTE_CRYPTO_AUTH_ZUC_EIA3: 544c5788a10SHemant Agrawal shared_desc_len = cnstr_shdsc_zuca( 545c5788a10SHemant Agrawal cdb->sh_desc, true, swap, 546c5788a10SHemant Agrawal &alginfo_a, 547c5788a10SHemant Agrawal !ses->dir, 548c5788a10SHemant Agrawal ses->digest_length); 549c5788a10SHemant Agrawal break; 55066f95673SGagandeep Singh case RTE_CRYPTO_AUTH_AES_XCBC_MAC: 5512ed12d9bSGagandeep Singh case RTE_CRYPTO_AUTH_AES_CMAC: 55266f95673SGagandeep Singh shared_desc_len = cnstr_shdsc_aes_mac( 55366f95673SGagandeep Singh cdb->sh_desc, 55466f95673SGagandeep Singh true, swap, SHR_NEVER, 55566f95673SGagandeep Singh &alginfo_a, 55666f95673SGagandeep Singh !ses->dir, 55766f95673SGagandeep Singh ses->digest_length); 55866f95673SGagandeep Singh break; 559c5788a10SHemant Agrawal default: 56077a9b5adSHemant Agrawal DPAA_SEC_ERR("unsupported auth alg %s (%u)", 56177a9b5adSHemant Agrawal rte_cryptodev_get_auth_algo_string(ses->auth_alg), 56277a9b5adSHemant Agrawal ses->auth_alg); 563c5788a10SHemant Agrawal } 5648524b44eSHemant Agrawal break; 5658524b44eSHemant Agrawal case DPAA_SEC_AEAD: 566c3e85bdcSAkhil Goyal if (alginfo.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) { 567f163231eSHemant Agrawal DPAA_SEC_ERR("not supported aead alg"); 568c3e85bdcSAkhil Goyal return -ENOTSUP; 569c3e85bdcSAkhil Goyal } 5700e5607e4SHemant Agrawal alginfo.key = (size_t)ses->aead_key.data; 571c3e85bdcSAkhil Goyal alginfo.keylen = ses->aead_key.length; 572c3e85bdcSAkhil Goyal alginfo.key_enc_flags = 0; 573c3e85bdcSAkhil Goyal alginfo.key_type = RTA_DATA_IMM; 5748524b44eSHemant Agrawal alginfo.algtype = ses->aead_key.alg; 5758524b44eSHemant Agrawal alginfo.algmode = ses->aead_key.algmode; 576c3e85bdcSAkhil Goyal 577c3e85bdcSAkhil Goyal if (ses->dir == DIR_ENC) 578c3e85bdcSAkhil Goyal shared_desc_len = cnstr_shdsc_gcm_encap( 5797449390bSAkhil Goyal cdb->sh_desc, true, swap, SHR_NEVER, 580c3e85bdcSAkhil Goyal &alginfo, 581c3e85bdcSAkhil Goyal ses->iv.length, 582c3e85bdcSAkhil Goyal ses->digest_length); 583c3e85bdcSAkhil Goyal else 584c3e85bdcSAkhil Goyal shared_desc_len = cnstr_shdsc_gcm_decap( 5857449390bSAkhil Goyal cdb->sh_desc, true, swap, SHR_NEVER, 586c3e85bdcSAkhil Goyal &alginfo, 587c3e85bdcSAkhil Goyal ses->iv.length, 588c3e85bdcSAkhil Goyal ses->digest_length); 5898524b44eSHemant Agrawal break; 5908524b44eSHemant Agrawal case DPAA_SEC_CIPHER_HASH: 5910e5607e4SHemant Agrawal alginfo_c.key = (size_t)ses->cipher_key.data; 592c3e85bdcSAkhil Goyal alginfo_c.keylen = ses->cipher_key.length; 593c3e85bdcSAkhil Goyal alginfo_c.key_enc_flags = 0; 594c3e85bdcSAkhil Goyal alginfo_c.key_type = RTA_DATA_IMM; 5958524b44eSHemant Agrawal alginfo_c.algtype = ses->cipher_key.alg; 5968524b44eSHemant Agrawal alginfo_c.algmode = ses->cipher_key.algmode; 597c3e85bdcSAkhil Goyal 5980e5607e4SHemant Agrawal alginfo_a.key = (size_t)ses->auth_key.data; 599c3e85bdcSAkhil Goyal alginfo_a.keylen = ses->auth_key.length; 600c3e85bdcSAkhil Goyal alginfo_a.key_enc_flags = 0; 601c3e85bdcSAkhil Goyal alginfo_a.key_type = RTA_DATA_IMM; 6028524b44eSHemant Agrawal alginfo_a.algtype = ses->auth_key.alg; 6038524b44eSHemant Agrawal alginfo_a.algmode = ses->auth_key.algmode; 604c3e85bdcSAkhil Goyal 605c3e85bdcSAkhil Goyal cdb->sh_desc[0] = alginfo_c.keylen; 606c3e85bdcSAkhil Goyal cdb->sh_desc[1] = alginfo_a.keylen; 607c3e85bdcSAkhil Goyal err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN, 608453b9593SAkhil Goyal DESC_JOB_IO_LEN, 609c3e85bdcSAkhil Goyal (unsigned int *)cdb->sh_desc, 610c3e85bdcSAkhil Goyal &cdb->sh_desc[2], 2); 611c3e85bdcSAkhil Goyal 612c3e85bdcSAkhil Goyal if (err < 0) { 613f163231eSHemant Agrawal DPAA_SEC_ERR("Crypto: Incorrect key lengths"); 614c3e85bdcSAkhil Goyal return err; 615c3e85bdcSAkhil Goyal } 616c3e85bdcSAkhil Goyal if (cdb->sh_desc[2] & 1) 617c3e85bdcSAkhil Goyal alginfo_c.key_type = RTA_DATA_IMM; 618c3e85bdcSAkhil Goyal else { 619ec861560SGagandeep Singh alginfo_c.key = (size_t)rte_dpaa_mem_vtop( 6200e5607e4SHemant Agrawal (void *)(size_t)alginfo_c.key); 621c3e85bdcSAkhil Goyal alginfo_c.key_type = RTA_DATA_PTR; 622c3e85bdcSAkhil Goyal } 623c3e85bdcSAkhil Goyal if (cdb->sh_desc[2] & (1<<1)) 624c3e85bdcSAkhil Goyal alginfo_a.key_type = RTA_DATA_IMM; 625c3e85bdcSAkhil Goyal else { 626ec861560SGagandeep Singh alginfo_a.key = (size_t)rte_dpaa_mem_vtop( 6270e5607e4SHemant Agrawal (void *)(size_t)alginfo_a.key); 628c3e85bdcSAkhil Goyal alginfo_a.key_type = RTA_DATA_PTR; 629c3e85bdcSAkhil Goyal } 630c3e85bdcSAkhil Goyal cdb->sh_desc[0] = 0; 631c3e85bdcSAkhil Goyal cdb->sh_desc[1] = 0; 632c3e85bdcSAkhil Goyal cdb->sh_desc[2] = 0; 6331f14d500SAkhil Goyal /* Auth_only_len is set as 0 here and it will be 6341f14d500SAkhil Goyal * overwritten in fd for each packet. 635c3e85bdcSAkhil Goyal */ 636c3e85bdcSAkhil Goyal shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc, 6377449390bSAkhil Goyal true, swap, SHR_SERIAL, &alginfo_c, &alginfo_a, 6383394ed47SVakul Garg ses->iv.length, 639c3e85bdcSAkhil Goyal ses->digest_length, ses->dir); 6408524b44eSHemant Agrawal break; 6418524b44eSHemant Agrawal default: 64277a9b5adSHemant Agrawal DPAA_SEC_ERR("error: Unsupported session %d", ses->ctxt); 6438524b44eSHemant Agrawal return -ENOTSUP; 644c3e85bdcSAkhil Goyal } 64522788c2cSSunil Kumar Kori 64622788c2cSSunil Kumar Kori if (shared_desc_len < 0) { 647f163231eSHemant Agrawal DPAA_SEC_ERR("error in preparing command block"); 64822788c2cSSunil Kumar Kori return shared_desc_len; 64922788c2cSSunil Kumar Kori } 65022788c2cSSunil Kumar Kori 651c3e85bdcSAkhil Goyal cdb->sh_hdr.hi.field.idlen = shared_desc_len; 652c3e85bdcSAkhil Goyal cdb->sh_hdr.hi.word = rte_cpu_to_be_32(cdb->sh_hdr.hi.word); 653c3e85bdcSAkhil Goyal cdb->sh_hdr.lo.word = rte_cpu_to_be_32(cdb->sh_hdr.lo.word); 654c3e85bdcSAkhil Goyal 655c3e85bdcSAkhil Goyal return 0; 656c3e85bdcSAkhil Goyal } 657c3e85bdcSAkhil Goyal 658b1bbf222SGagandeep Singh static void 659a8794e39SHemant Agrawal dpaa_sec_dump(struct dpaa_sec_op_ctx *ctx, struct dpaa_sec_qp *qp, FILE *f) 660b1bbf222SGagandeep Singh { 661b1bbf222SGagandeep Singh struct dpaa_sec_job *job = &ctx->job; 662b1bbf222SGagandeep Singh struct rte_crypto_op *op = ctx->op; 663b1bbf222SGagandeep Singh dpaa_sec_session *sess = NULL; 664b1bbf222SGagandeep Singh struct sec_cdb c_cdb, *cdb; 665b1bbf222SGagandeep Singh uint8_t bufsize; 666b1bbf222SGagandeep Singh struct rte_crypto_sym_op *sym_op; 667b1bbf222SGagandeep Singh struct qm_sg_entry sg[2]; 668b1bbf222SGagandeep Singh 669b1bbf222SGagandeep Singh if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) 6702a440d6aSAkhil Goyal sess = CRYPTODEV_GET_SYM_SESS_PRIV(op->sym->session); 6714331f814SDavid Marchand #ifdef RTE_LIB_SECURITY 672b1bbf222SGagandeep Singh else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) 6732973dbf9SAkhil Goyal sess = SECURITY_GET_SESS_PRIV(op->sym->session); 674b1bbf222SGagandeep Singh #endif 675b1bbf222SGagandeep Singh if (sess == NULL) { 676b1bbf222SGagandeep Singh printf("session is NULL\n"); 677b1bbf222SGagandeep Singh goto mbuf_dump; 678b1bbf222SGagandeep Singh } 679b1bbf222SGagandeep Singh 680b1bbf222SGagandeep Singh cdb = &sess->cdb; 681b1bbf222SGagandeep Singh rte_memcpy(&c_cdb, cdb, sizeof(struct sec_cdb)); 6824331f814SDavid Marchand #ifdef RTE_LIB_SECURITY 683a8794e39SHemant Agrawal fprintf(f, "\nsession protocol type = %d\n", sess->proto_alg); 684b1bbf222SGagandeep Singh #endif 685a8794e39SHemant Agrawal fprintf(f, "\n****************************************\n" 686b1bbf222SGagandeep Singh "session params:\n\tContext type:\t%d\n\tDirection:\t%s\n" 687b1bbf222SGagandeep Singh "\tCipher alg:\t%d\n\tAuth alg:\t%d\n\tAead alg:\t%d\n" 688b1bbf222SGagandeep Singh "\tCipher key len:\t%"PRIu64"\n\tCipher alg:\t%d\n" 689b1bbf222SGagandeep Singh "\tCipher algmode:\t%d\n", sess->ctxt, 690b1bbf222SGagandeep Singh (sess->dir == DIR_ENC) ? "DIR_ENC" : "DIR_DEC", 691b1bbf222SGagandeep Singh sess->cipher_alg, sess->auth_alg, sess->aead_alg, 692b1bbf222SGagandeep Singh (uint64_t)sess->cipher_key.length, sess->cipher_key.alg, 693b1bbf222SGagandeep Singh sess->cipher_key.algmode); 694a8794e39SHemant Agrawal rte_hexdump(f, "cipher key", sess->cipher_key.data, 695b1bbf222SGagandeep Singh sess->cipher_key.length); 696a8794e39SHemant Agrawal rte_hexdump(f, "auth key", sess->auth_key.data, 697b1bbf222SGagandeep Singh sess->auth_key.length); 698a8794e39SHemant Agrawal fprintf(f, "\tAuth key len:\t%"PRIu64"\n\tAuth alg:\t%d\n" 699b1bbf222SGagandeep Singh "\tAuth algmode:\t%d\n\tIV len:\t\t%d\n\tIV offset:\t%d\n" 700b1bbf222SGagandeep Singh "\tdigest length:\t%d\n\tauth only len:\t\t%d\n" 701b1bbf222SGagandeep Singh "\taead cipher text:\t%d\n", 702b1bbf222SGagandeep Singh (uint64_t)sess->auth_key.length, sess->auth_key.alg, 703b1bbf222SGagandeep Singh sess->auth_key.algmode, 704b1bbf222SGagandeep Singh sess->iv.length, sess->iv.offset, 705b1bbf222SGagandeep Singh sess->digest_length, sess->auth_only_len, 706b1bbf222SGagandeep Singh sess->auth_cipher_text); 7074331f814SDavid Marchand #ifdef RTE_LIB_SECURITY 708a8794e39SHemant Agrawal fprintf(f, "PDCP session params:\n" 709b1bbf222SGagandeep Singh "\tDomain:\t\t%d\n\tBearer:\t\t%d\n\tpkt_dir:\t%d\n\thfn_ovd:" 710b1bbf222SGagandeep Singh "\t%d\n\tsn_size:\t%d\n\tsdap_enabled:\t%d\n\thfn_ovd_offset:" 711b1bbf222SGagandeep Singh "\t%d\n\thfn:\t\t%d\n" 712b1bbf222SGagandeep Singh "\thfn_threshold:\t0x%x\n", sess->pdcp.domain, 713b1bbf222SGagandeep Singh sess->pdcp.bearer, sess->pdcp.pkt_dir, sess->pdcp.hfn_ovd, 714b1bbf222SGagandeep Singh sess->pdcp.sn_size, sess->pdcp.sdap_enabled, 715b1bbf222SGagandeep Singh sess->pdcp.hfn_ovd_offset, sess->pdcp.hfn, 716b1bbf222SGagandeep Singh sess->pdcp.hfn_threshold); 717b1bbf222SGagandeep Singh #endif 718b1bbf222SGagandeep Singh c_cdb.sh_hdr.hi.word = rte_be_to_cpu_32(c_cdb.sh_hdr.hi.word); 719b1bbf222SGagandeep Singh c_cdb.sh_hdr.lo.word = rte_be_to_cpu_32(c_cdb.sh_hdr.lo.word); 720b1bbf222SGagandeep Singh bufsize = c_cdb.sh_hdr.hi.field.idlen; 721b1bbf222SGagandeep Singh 722a8794e39SHemant Agrawal fprintf(f, "cdb = %p\n\n", cdb); 723a8794e39SHemant Agrawal fprintf(f, "Descriptor size = %d\n", bufsize); 724b1bbf222SGagandeep Singh int m; 725b1bbf222SGagandeep Singh for (m = 0; m < bufsize; m++) 726a8794e39SHemant Agrawal fprintf(f, "0x%x\n", rte_be_to_cpu_32(c_cdb.sh_desc[m])); 727b1bbf222SGagandeep Singh 728a8794e39SHemant Agrawal fprintf(f, "\n"); 729b1bbf222SGagandeep Singh mbuf_dump: 730b1bbf222SGagandeep Singh sym_op = op->sym; 731b1bbf222SGagandeep Singh if (sym_op->m_src) { 732a8794e39SHemant Agrawal fprintf(f, "Source mbuf:\n"); 733a8794e39SHemant Agrawal rte_pktmbuf_dump(f, sym_op->m_src, 734b1bbf222SGagandeep Singh sym_op->m_src->data_len); 735b1bbf222SGagandeep Singh } 736b1bbf222SGagandeep Singh if (sym_op->m_dst) { 737a8794e39SHemant Agrawal fprintf(f, "Destination mbuf:\n"); 738a8794e39SHemant Agrawal rte_pktmbuf_dump(f, sym_op->m_dst, 739b1bbf222SGagandeep Singh sym_op->m_dst->data_len); 740b1bbf222SGagandeep Singh } 741b1bbf222SGagandeep Singh 742a8794e39SHemant Agrawal fprintf(f, "Session address = %p\ncipher offset: %d, length: %d\n" 743b1bbf222SGagandeep Singh "auth offset: %d, length: %d\n aead offset: %d, length: %d\n", 744b1bbf222SGagandeep Singh sym_op->session, sym_op->cipher.data.offset, 745b1bbf222SGagandeep Singh sym_op->cipher.data.length, 746b1bbf222SGagandeep Singh sym_op->auth.data.offset, sym_op->auth.data.length, 747b1bbf222SGagandeep Singh sym_op->aead.data.offset, sym_op->aead.data.length); 748a8794e39SHemant Agrawal fprintf(f, "\n"); 749b1bbf222SGagandeep Singh 750a8794e39SHemant Agrawal fprintf(f, "******************************************************\n"); 751a8794e39SHemant Agrawal fprintf(f, "ctx info:\n"); 752a8794e39SHemant Agrawal fprintf(f, "job->sg[0] output info:\n"); 753b1bbf222SGagandeep Singh memcpy(&sg[0], &job->sg[0], sizeof(sg[0])); 754a8794e39SHemant Agrawal fprintf(f, "\taddr = %"PRIx64",\n\tlen = %d,\n\tfinal = %d,\n\textension = %d" 755b1bbf222SGagandeep Singh "\n\tbpid = %d\n\toffset = %d\n", 756b1bbf222SGagandeep Singh (uint64_t)sg[0].addr, sg[0].length, sg[0].final, 757b1bbf222SGagandeep Singh sg[0].extension, sg[0].bpid, sg[0].offset); 758a8794e39SHemant Agrawal fprintf(f, "\njob->sg[1] input info:\n"); 759b1bbf222SGagandeep Singh memcpy(&sg[1], &job->sg[1], sizeof(sg[1])); 760b1bbf222SGagandeep Singh hw_sg_to_cpu(&sg[1]); 761a8794e39SHemant Agrawal fprintf(f, "\taddr = %"PRIx64",\n\tlen = %d,\n\tfinal = %d,\n\textension = %d" 762b1bbf222SGagandeep Singh "\n\tbpid = %d\n\toffset = %d\n", 763b1bbf222SGagandeep Singh (uint64_t)sg[1].addr, sg[1].length, sg[1].final, 764b1bbf222SGagandeep Singh sg[1].extension, sg[1].bpid, sg[1].offset); 765b1bbf222SGagandeep Singh 766a8794e39SHemant Agrawal fprintf(f, "\nctx pool addr = %p\n", ctx->ctx_pool); 767b1bbf222SGagandeep Singh if (ctx->ctx_pool) 768a8794e39SHemant Agrawal fprintf(f, "ctx pool available counts = %d\n", 769b1bbf222SGagandeep Singh rte_mempool_avail_count(ctx->ctx_pool)); 770b1bbf222SGagandeep Singh 771a8794e39SHemant Agrawal fprintf(f, "\nop pool addr = %p\n", op->mempool); 772b1bbf222SGagandeep Singh if (op->mempool) 773a8794e39SHemant Agrawal fprintf(f, "op pool available counts = %d\n", 774b1bbf222SGagandeep Singh rte_mempool_avail_count(op->mempool)); 775b1bbf222SGagandeep Singh 776a8794e39SHemant Agrawal fprintf(f, "********************************************************\n"); 777a8794e39SHemant Agrawal fprintf(f, "Queue data:\n"); 778a8794e39SHemant Agrawal fprintf(f, "\tFQID = 0x%x\n\tstate = %d\n\tnb_desc = %d\n" 779b1bbf222SGagandeep Singh "\tctx_pool = %p\n\trx_pkts = %d\n\ttx_pkts" 780b1bbf222SGagandeep Singh "= %d\n\trx_errs = %d\n\ttx_errs = %d\n\n", 781b1bbf222SGagandeep Singh qp->outq.fqid, qp->outq.state, qp->outq.nb_desc, 782b1bbf222SGagandeep Singh qp->ctx_pool, qp->rx_pkts, qp->tx_pkts, 783b1bbf222SGagandeep Singh qp->rx_errs, qp->tx_errs); 784b1bbf222SGagandeep Singh } 785b1bbf222SGagandeep Singh 786c3e85bdcSAkhil Goyal /* qp is lockless, should be accessed by only one thread */ 787c3e85bdcSAkhil Goyal static int 788c3e85bdcSAkhil Goyal dpaa_sec_deq(struct dpaa_sec_qp *qp, struct rte_crypto_op **ops, int nb_ops) 789c3e85bdcSAkhil Goyal { 790c3e85bdcSAkhil Goyal struct qman_fq *fq; 7919a984458SAkhil Goyal unsigned int pkts = 0; 792f40d5a53SNipun Gupta int num_rx_bufs, ret; 7939a984458SAkhil Goyal struct qm_dqrr_entry *dq; 794f40d5a53SNipun Gupta uint32_t vdqcr_flags = 0; 795c3e85bdcSAkhil Goyal 796c3e85bdcSAkhil Goyal fq = &qp->outq; 797f40d5a53SNipun Gupta /* 798f40d5a53SNipun Gupta * Until request for four buffers, we provide exact number of buffers. 799f40d5a53SNipun Gupta * Otherwise we do not set the QM_VDQCR_EXACT flag. 800f40d5a53SNipun Gupta * Not setting QM_VDQCR_EXACT flag can provide two more buffers than 801f40d5a53SNipun Gupta * requested, so we request two less in this case. 802f40d5a53SNipun Gupta */ 803f40d5a53SNipun Gupta if (nb_ops < 4) { 804f40d5a53SNipun Gupta vdqcr_flags = QM_VDQCR_EXACT; 805f40d5a53SNipun Gupta num_rx_bufs = nb_ops; 806f40d5a53SNipun Gupta } else { 807f40d5a53SNipun Gupta num_rx_bufs = nb_ops > DPAA_MAX_DEQUEUE_NUM_FRAMES ? 808f40d5a53SNipun Gupta (DPAA_MAX_DEQUEUE_NUM_FRAMES - 2) : (nb_ops - 2); 809f40d5a53SNipun Gupta } 810f40d5a53SNipun Gupta ret = qman_set_vdq(fq, num_rx_bufs, vdqcr_flags); 8119a984458SAkhil Goyal if (ret) 8129a984458SAkhil Goyal return 0; 813c3e85bdcSAkhil Goyal 8149a984458SAkhil Goyal do { 8159a984458SAkhil Goyal const struct qm_fd *fd; 8169a984458SAkhil Goyal struct dpaa_sec_job *job; 8179a984458SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 8189a984458SAkhil Goyal struct rte_crypto_op *op; 819c3e85bdcSAkhil Goyal 8209a984458SAkhil Goyal dq = qman_dequeue(fq); 8219a984458SAkhil Goyal if (!dq) 8229a984458SAkhil Goyal continue; 8239a984458SAkhil Goyal 8249a984458SAkhil Goyal fd = &dq->fd; 8259a984458SAkhil Goyal /* sg is embedded in an op ctx, 8269a984458SAkhil Goyal * sg[0] is for output 8279a984458SAkhil Goyal * sg[1] for input 8289a984458SAkhil Goyal */ 829ec861560SGagandeep Singh job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd)); 8309a984458SAkhil Goyal 8319a984458SAkhil Goyal ctx = container_of(job, struct dpaa_sec_op_ctx, job); 8329a984458SAkhil Goyal ctx->fd_status = fd->status; 8339a984458SAkhil Goyal op = ctx->op; 8349a984458SAkhil Goyal if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) { 8359a984458SAkhil Goyal struct qm_sg_entry *sg_out; 8369a984458SAkhil Goyal uint32_t len; 837fb5c100aSAkhil Goyal struct rte_mbuf *mbuf = (op->sym->m_dst == NULL) ? 838fb5c100aSAkhil Goyal op->sym->m_src : op->sym->m_dst; 8399a984458SAkhil Goyal 8409a984458SAkhil Goyal sg_out = &job->sg[0]; 8419a984458SAkhil Goyal hw_sg_to_cpu(sg_out); 8429a984458SAkhil Goyal len = sg_out->length; 843fb5c100aSAkhil Goyal mbuf->pkt_len = len; 844fb5c100aSAkhil Goyal while (mbuf->next != NULL) { 845fb5c100aSAkhil Goyal len -= mbuf->data_len; 846fb5c100aSAkhil Goyal mbuf = mbuf->next; 847fb5c100aSAkhil Goyal } 848fb5c100aSAkhil Goyal mbuf->data_len = len; 8499a984458SAkhil Goyal } 8509a984458SAkhil Goyal if (!ctx->fd_status) { 8519a984458SAkhil Goyal op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 8529a984458SAkhil Goyal } else { 853b1bbf222SGagandeep Singh if (dpaa_sec_dp_dump > DPAA_SEC_DP_NO_DUMP) { 854*f665790aSDavid Marchand DPAA_SEC_DP_WARN("SEC return err:0x%x", 855b1bbf222SGagandeep Singh ctx->fd_status); 856b1bbf222SGagandeep Singh if (dpaa_sec_dp_dump > DPAA_SEC_DP_ERR_DUMP) 857a8794e39SHemant Agrawal dpaa_sec_dump(ctx, qp, stdout); 858b1bbf222SGagandeep Singh } 8599a984458SAkhil Goyal op->status = RTE_CRYPTO_OP_STATUS_ERROR; 8609a984458SAkhil Goyal } 8619a984458SAkhil Goyal ops[pkts++] = op; 8629a984458SAkhil Goyal 8637be78d02SJosh Soref /* report op status to sym->op and then free the ctx memory */ 8649a984458SAkhil Goyal rte_mempool_put(ctx->ctx_pool, (void *)ctx); 8659a984458SAkhil Goyal 8669a984458SAkhil Goyal qman_dqrr_consume(fq, dq); 8679a984458SAkhil Goyal } while (fq->flags & QMAN_FQ_STATE_VDQCR); 8689a984458SAkhil Goyal 8699a984458SAkhil Goyal return pkts; 870c3e85bdcSAkhil Goyal } 871c3e85bdcSAkhil Goyal 872a74af788SAkhil Goyal static inline struct dpaa_sec_job * 873a74af788SAkhil Goyal build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses) 874a74af788SAkhil Goyal { 875a74af788SAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 876a74af788SAkhil Goyal struct rte_mbuf *mbuf = sym->m_src; 877a74af788SAkhil Goyal struct dpaa_sec_job *cf; 878a74af788SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 879a74af788SAkhil Goyal struct qm_sg_entry *sg, *out_sg, *in_sg; 880a74af788SAkhil Goyal phys_addr_t start_addr; 881a74af788SAkhil Goyal uint8_t *old_digest, extra_segs; 882c5788a10SHemant Agrawal int data_len, data_offset; 883c5788a10SHemant Agrawal 884c5788a10SHemant Agrawal data_len = sym->auth.data.length; 885c5788a10SHemant Agrawal data_offset = sym->auth.data.offset; 886c5788a10SHemant Agrawal 887c5788a10SHemant Agrawal if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 888c5788a10SHemant Agrawal ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) { 889c5788a10SHemant Agrawal if ((data_len & 7) || (data_offset & 7)) { 890c5788a10SHemant Agrawal DPAA_SEC_ERR("AUTH: len/offset must be full bytes"); 891c5788a10SHemant Agrawal return NULL; 892c5788a10SHemant Agrawal } 893c5788a10SHemant Agrawal 894c5788a10SHemant Agrawal data_len = data_len >> 3; 895c5788a10SHemant Agrawal data_offset = data_offset >> 3; 896c5788a10SHemant Agrawal } 897a74af788SAkhil Goyal 898a74af788SAkhil Goyal if (is_decode(ses)) 899a74af788SAkhil Goyal extra_segs = 3; 900a74af788SAkhil Goyal else 901a74af788SAkhil Goyal extra_segs = 2; 902a74af788SAkhil Goyal 903f7a5752eSHemant Agrawal if (mbuf->nb_segs > MAX_SG_ENTRIES) { 904f163231eSHemant Agrawal DPAA_SEC_DP_ERR("Auth: Max sec segs supported is %d", 905a74af788SAkhil Goyal MAX_SG_ENTRIES); 906a74af788SAkhil Goyal return NULL; 907a74af788SAkhil Goyal } 908f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, mbuf->nb_segs + extra_segs); 909a74af788SAkhil Goyal if (!ctx) 910a74af788SAkhil Goyal return NULL; 911a74af788SAkhil Goyal 912a74af788SAkhil Goyal cf = &ctx->job; 913a74af788SAkhil Goyal ctx->op = op; 914a74af788SAkhil Goyal old_digest = ctx->digest; 915a74af788SAkhil Goyal 916a74af788SAkhil Goyal /* output */ 917a74af788SAkhil Goyal out_sg = &cf->sg[0]; 918a74af788SAkhil Goyal qm_sg_entry_set64(out_sg, sym->auth.digest.phys_addr); 919a74af788SAkhil Goyal out_sg->length = ses->digest_length; 920a74af788SAkhil Goyal cpu_to_hw_sg(out_sg); 921a74af788SAkhil Goyal 922a74af788SAkhil Goyal /* input */ 923a74af788SAkhil Goyal in_sg = &cf->sg[1]; 924a74af788SAkhil Goyal /* need to extend the input to a compound frame */ 925a74af788SAkhil Goyal in_sg->extension = 1; 926a74af788SAkhil Goyal in_sg->final = 1; 927c5788a10SHemant Agrawal in_sg->length = data_len; 928ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2])); 929a74af788SAkhil Goyal 930a74af788SAkhil Goyal /* 1st seg */ 931a74af788SAkhil Goyal sg = in_sg + 1; 932a74af788SAkhil Goyal 933c5788a10SHemant Agrawal if (ses->iv.length) { 934c5788a10SHemant Agrawal uint8_t *iv_ptr; 935c5788a10SHemant Agrawal 936c5788a10SHemant Agrawal iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 937c5788a10SHemant Agrawal ses->iv.offset); 938c5788a10SHemant Agrawal 939c5788a10SHemant Agrawal if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) { 940c5788a10SHemant Agrawal iv_ptr = conv_to_snow_f9_iv(iv_ptr); 941c5788a10SHemant Agrawal sg->length = 12; 942c5788a10SHemant Agrawal } else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) { 943c5788a10SHemant Agrawal iv_ptr = conv_to_zuc_eia_iv(iv_ptr); 944c5788a10SHemant Agrawal sg->length = 8; 945c5788a10SHemant Agrawal } else { 946c5788a10SHemant Agrawal sg->length = ses->iv.length; 947c5788a10SHemant Agrawal } 948ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr)); 949c5788a10SHemant Agrawal in_sg->length += sg->length; 950c5788a10SHemant Agrawal cpu_to_hw_sg(sg); 951c5788a10SHemant Agrawal sg++; 952c5788a10SHemant Agrawal } 953c5788a10SHemant Agrawal 954ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 955c5788a10SHemant Agrawal sg->offset = data_offset; 956c5788a10SHemant Agrawal 957c5788a10SHemant Agrawal if (data_len <= (mbuf->data_len - data_offset)) { 958c5788a10SHemant Agrawal sg->length = data_len; 959c5788a10SHemant Agrawal } else { 960c5788a10SHemant Agrawal sg->length = mbuf->data_len - data_offset; 961c5788a10SHemant Agrawal 962c5788a10SHemant Agrawal /* remaining i/p segs */ 963c5788a10SHemant Agrawal while ((data_len = data_len - sg->length) && 964c5788a10SHemant Agrawal (mbuf = mbuf->next)) { 965a74af788SAkhil Goyal cpu_to_hw_sg(sg); 966a74af788SAkhil Goyal sg++; 967ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 968c5788a10SHemant Agrawal if (data_len > mbuf->data_len) 969a74af788SAkhil Goyal sg->length = mbuf->data_len; 970c5788a10SHemant Agrawal else 971c5788a10SHemant Agrawal sg->length = data_len; 972c5788a10SHemant Agrawal } 973a74af788SAkhil Goyal } 974a74af788SAkhil Goyal 975a74af788SAkhil Goyal if (is_decode(ses)) { 976a74af788SAkhil Goyal /* Digest verification case */ 977a74af788SAkhil Goyal cpu_to_hw_sg(sg); 978a74af788SAkhil Goyal sg++; 979a74af788SAkhil Goyal rte_memcpy(old_digest, sym->auth.digest.data, 980a74af788SAkhil Goyal ses->digest_length); 981ec861560SGagandeep Singh start_addr = rte_dpaa_mem_vtop(old_digest); 982a74af788SAkhil Goyal qm_sg_entry_set64(sg, start_addr); 983a74af788SAkhil Goyal sg->length = ses->digest_length; 984a74af788SAkhil Goyal in_sg->length += ses->digest_length; 985a74af788SAkhil Goyal } 986a74af788SAkhil Goyal sg->final = 1; 987a74af788SAkhil Goyal cpu_to_hw_sg(sg); 988a74af788SAkhil Goyal cpu_to_hw_sg(in_sg); 989a74af788SAkhil Goyal 990a74af788SAkhil Goyal return cf; 991a74af788SAkhil Goyal } 992a74af788SAkhil Goyal 993c3e85bdcSAkhil Goyal /** 994c3e85bdcSAkhil Goyal * packet looks like: 995c3e85bdcSAkhil Goyal * |<----data_len------->| 996c3e85bdcSAkhil Goyal * |ip_header|ah_header|icv|payload| 997c3e85bdcSAkhil Goyal * ^ 998c3e85bdcSAkhil Goyal * | 999c3e85bdcSAkhil Goyal * mbuf->pkt.data 1000c3e85bdcSAkhil Goyal */ 1001c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job * 1002c3e85bdcSAkhil Goyal build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses) 1003c3e85bdcSAkhil Goyal { 1004c3e85bdcSAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1005c3e85bdcSAkhil Goyal struct rte_mbuf *mbuf = sym->m_src; 1006c3e85bdcSAkhil Goyal struct dpaa_sec_job *cf; 1007c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1008c5788a10SHemant Agrawal struct qm_sg_entry *sg, *in_sg; 1009c4509373SSantosh Shukla rte_iova_t start_addr; 1010c3e85bdcSAkhil Goyal uint8_t *old_digest; 1011c5788a10SHemant Agrawal int data_len, data_offset; 1012c5788a10SHemant Agrawal 1013c5788a10SHemant Agrawal data_len = sym->auth.data.length; 1014c5788a10SHemant Agrawal data_offset = sym->auth.data.offset; 1015c5788a10SHemant Agrawal 1016c5788a10SHemant Agrawal if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 1017c5788a10SHemant Agrawal ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) { 1018c5788a10SHemant Agrawal if ((data_len & 7) || (data_offset & 7)) { 1019c5788a10SHemant Agrawal DPAA_SEC_ERR("AUTH: len/offset must be full bytes"); 1020c5788a10SHemant Agrawal return NULL; 1021c5788a10SHemant Agrawal } 1022c5788a10SHemant Agrawal 1023c5788a10SHemant Agrawal data_len = data_len >> 3; 1024c5788a10SHemant Agrawal data_offset = data_offset >> 3; 1025c5788a10SHemant Agrawal } 1026c3e85bdcSAkhil Goyal 1027f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, 4); 1028c3e85bdcSAkhil Goyal if (!ctx) 1029c3e85bdcSAkhil Goyal return NULL; 1030c3e85bdcSAkhil Goyal 1031c3e85bdcSAkhil Goyal cf = &ctx->job; 1032c3e85bdcSAkhil Goyal ctx->op = op; 1033c3e85bdcSAkhil Goyal old_digest = ctx->digest; 1034c3e85bdcSAkhil Goyal 1035bfa9a8a4SThomas Monjalon start_addr = rte_pktmbuf_iova(mbuf); 1036c3e85bdcSAkhil Goyal /* output */ 1037c3e85bdcSAkhil Goyal sg = &cf->sg[0]; 1038c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, sym->auth.digest.phys_addr); 1039c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1040c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1041c3e85bdcSAkhil Goyal 1042c3e85bdcSAkhil Goyal /* input */ 1043c5788a10SHemant Agrawal in_sg = &cf->sg[1]; 1044c3e85bdcSAkhil Goyal /* need to extend the input to a compound frame */ 1045c5788a10SHemant Agrawal in_sg->extension = 1; 1046c5788a10SHemant Agrawal in_sg->final = 1; 1047c5788a10SHemant Agrawal in_sg->length = data_len; 1048ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2])); 1049c3e85bdcSAkhil Goyal sg = &cf->sg[2]; 1050c5788a10SHemant Agrawal 1051c5788a10SHemant Agrawal if (ses->iv.length) { 1052c5788a10SHemant Agrawal uint8_t *iv_ptr; 1053c5788a10SHemant Agrawal 1054c5788a10SHemant Agrawal iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1055c5788a10SHemant Agrawal ses->iv.offset); 1056c5788a10SHemant Agrawal 1057c5788a10SHemant Agrawal if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) { 1058c5788a10SHemant Agrawal iv_ptr = conv_to_snow_f9_iv(iv_ptr); 1059c5788a10SHemant Agrawal sg->length = 12; 1060c5788a10SHemant Agrawal } else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) { 1061c5788a10SHemant Agrawal iv_ptr = conv_to_zuc_eia_iv(iv_ptr); 1062c5788a10SHemant Agrawal sg->length = 8; 1063c5788a10SHemant Agrawal } else { 1064c5788a10SHemant Agrawal sg->length = ses->iv.length; 1065c5788a10SHemant Agrawal } 1066ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr)); 1067c5788a10SHemant Agrawal in_sg->length += sg->length; 1068c5788a10SHemant Agrawal cpu_to_hw_sg(sg); 1069c5788a10SHemant Agrawal sg++; 1070c5788a10SHemant Agrawal } 1071c5788a10SHemant Agrawal 1072ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1073c5788a10SHemant Agrawal sg->offset = data_offset; 1074c5788a10SHemant Agrawal sg->length = data_len; 1075c5788a10SHemant Agrawal 1076c5788a10SHemant Agrawal if (is_decode(ses)) { 1077c5788a10SHemant Agrawal /* Digest verification case */ 1078c5788a10SHemant Agrawal cpu_to_hw_sg(sg); 1079c3e85bdcSAkhil Goyal /* hash result or digest, save digest first */ 1080c3e85bdcSAkhil Goyal rte_memcpy(old_digest, sym->auth.digest.data, 1081c3e85bdcSAkhil Goyal ses->digest_length); 1082c3e85bdcSAkhil Goyal /* let's check digest by hw */ 1083ec861560SGagandeep Singh start_addr = rte_dpaa_mem_vtop(old_digest); 1084c3e85bdcSAkhil Goyal sg++; 1085c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, start_addr); 1086c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1087c5788a10SHemant Agrawal in_sg->length += ses->digest_length; 1088c3e85bdcSAkhil Goyal } 1089c5788a10SHemant Agrawal sg->final = 1; 1090c5788a10SHemant Agrawal cpu_to_hw_sg(sg); 1091c5788a10SHemant Agrawal cpu_to_hw_sg(in_sg); 1092c3e85bdcSAkhil Goyal 1093c3e85bdcSAkhil Goyal return cf; 1094c3e85bdcSAkhil Goyal } 1095c3e85bdcSAkhil Goyal 1096c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job * 1097a74af788SAkhil Goyal build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses) 1098a74af788SAkhil Goyal { 1099a74af788SAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1100a74af788SAkhil Goyal struct dpaa_sec_job *cf; 1101a74af788SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1102a74af788SAkhil Goyal struct qm_sg_entry *sg, *out_sg, *in_sg; 1103a74af788SAkhil Goyal struct rte_mbuf *mbuf; 1104a74af788SAkhil Goyal uint8_t req_segs; 1105a74af788SAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1106a74af788SAkhil Goyal ses->iv.offset); 1107c5788a10SHemant Agrawal int data_len, data_offset; 1108c5788a10SHemant Agrawal 1109c5788a10SHemant Agrawal data_len = sym->cipher.data.length; 1110c5788a10SHemant Agrawal data_offset = sym->cipher.data.offset; 1111c5788a10SHemant Agrawal 1112c5788a10SHemant Agrawal if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 1113c5788a10SHemant Agrawal ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 1114c5788a10SHemant Agrawal if ((data_len & 7) || (data_offset & 7)) { 1115c5788a10SHemant Agrawal DPAA_SEC_ERR("CIPHER: len/offset must be full bytes"); 1116c5788a10SHemant Agrawal return NULL; 1117c5788a10SHemant Agrawal } 1118c5788a10SHemant Agrawal 1119c5788a10SHemant Agrawal data_len = data_len >> 3; 1120c5788a10SHemant Agrawal data_offset = data_offset >> 3; 1121c5788a10SHemant Agrawal } 1122a74af788SAkhil Goyal 1123a74af788SAkhil Goyal if (sym->m_dst) { 1124a74af788SAkhil Goyal mbuf = sym->m_dst; 1125a74af788SAkhil Goyal req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 3; 1126a74af788SAkhil Goyal } else { 1127a74af788SAkhil Goyal mbuf = sym->m_src; 1128a74af788SAkhil Goyal req_segs = mbuf->nb_segs * 2 + 3; 1129a74af788SAkhil Goyal } 1130f7a5752eSHemant Agrawal if (mbuf->nb_segs > MAX_SG_ENTRIES) { 1131f163231eSHemant Agrawal DPAA_SEC_DP_ERR("Cipher: Max sec segs supported is %d", 1132a74af788SAkhil Goyal MAX_SG_ENTRIES); 1133a74af788SAkhil Goyal return NULL; 1134a74af788SAkhil Goyal } 1135a74af788SAkhil Goyal 1136f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, req_segs); 1137a74af788SAkhil Goyal if (!ctx) 1138a74af788SAkhil Goyal return NULL; 1139a74af788SAkhil Goyal 1140a74af788SAkhil Goyal cf = &ctx->job; 1141a74af788SAkhil Goyal ctx->op = op; 1142a74af788SAkhil Goyal 1143a74af788SAkhil Goyal /* output */ 1144a74af788SAkhil Goyal out_sg = &cf->sg[0]; 1145a74af788SAkhil Goyal out_sg->extension = 1; 1146c5788a10SHemant Agrawal out_sg->length = data_len; 1147ec861560SGagandeep Singh qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2])); 1148a74af788SAkhil Goyal cpu_to_hw_sg(out_sg); 1149a74af788SAkhil Goyal 1150a74af788SAkhil Goyal /* 1st seg */ 1151a74af788SAkhil Goyal sg = &cf->sg[2]; 1152ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1153c5788a10SHemant Agrawal sg->length = mbuf->data_len - data_offset; 1154c5788a10SHemant Agrawal sg->offset = data_offset; 1155a74af788SAkhil Goyal 1156a74af788SAkhil Goyal /* Successive segs */ 1157a74af788SAkhil Goyal mbuf = mbuf->next; 1158a74af788SAkhil Goyal while (mbuf) { 1159a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1160a74af788SAkhil Goyal sg++; 1161ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1162a74af788SAkhil Goyal sg->length = mbuf->data_len; 1163a74af788SAkhil Goyal mbuf = mbuf->next; 1164a74af788SAkhil Goyal } 1165a74af788SAkhil Goyal sg->final = 1; 1166a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1167a74af788SAkhil Goyal 1168a74af788SAkhil Goyal /* input */ 1169a74af788SAkhil Goyal mbuf = sym->m_src; 1170a74af788SAkhil Goyal in_sg = &cf->sg[1]; 1171a74af788SAkhil Goyal in_sg->extension = 1; 1172a74af788SAkhil Goyal in_sg->final = 1; 1173c5788a10SHemant Agrawal in_sg->length = data_len + ses->iv.length; 1174a74af788SAkhil Goyal 1175a74af788SAkhil Goyal sg++; 1176ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg)); 1177a74af788SAkhil Goyal cpu_to_hw_sg(in_sg); 1178a74af788SAkhil Goyal 1179a74af788SAkhil Goyal /* IV */ 1180ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1181a74af788SAkhil Goyal sg->length = ses->iv.length; 1182a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1183a74af788SAkhil Goyal 1184a74af788SAkhil Goyal /* 1st seg */ 1185a74af788SAkhil Goyal sg++; 1186ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1187c5788a10SHemant Agrawal sg->length = mbuf->data_len - data_offset; 1188c5788a10SHemant Agrawal sg->offset = data_offset; 1189a74af788SAkhil Goyal 1190a74af788SAkhil Goyal /* Successive segs */ 1191a74af788SAkhil Goyal mbuf = mbuf->next; 1192a74af788SAkhil Goyal while (mbuf) { 1193a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1194a74af788SAkhil Goyal sg++; 1195ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1196a74af788SAkhil Goyal sg->length = mbuf->data_len; 1197a74af788SAkhil Goyal mbuf = mbuf->next; 1198a74af788SAkhil Goyal } 1199a74af788SAkhil Goyal sg->final = 1; 1200a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1201a74af788SAkhil Goyal 1202a74af788SAkhil Goyal return cf; 1203a74af788SAkhil Goyal } 1204a74af788SAkhil Goyal 1205a74af788SAkhil Goyal static inline struct dpaa_sec_job * 1206c3e85bdcSAkhil Goyal build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses) 1207c3e85bdcSAkhil Goyal { 1208c3e85bdcSAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1209c3e85bdcSAkhil Goyal struct dpaa_sec_job *cf; 1210c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1211c3e85bdcSAkhil Goyal struct qm_sg_entry *sg; 1212c4509373SSantosh Shukla rte_iova_t src_start_addr, dst_start_addr; 1213c3e85bdcSAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1214c3e85bdcSAkhil Goyal ses->iv.offset); 1215c5788a10SHemant Agrawal int data_len, data_offset; 1216c5788a10SHemant Agrawal 1217c5788a10SHemant Agrawal data_len = sym->cipher.data.length; 1218c5788a10SHemant Agrawal data_offset = sym->cipher.data.offset; 1219c5788a10SHemant Agrawal 1220c5788a10SHemant Agrawal if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 1221c5788a10SHemant Agrawal ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 1222c5788a10SHemant Agrawal if ((data_len & 7) || (data_offset & 7)) { 1223c5788a10SHemant Agrawal DPAA_SEC_ERR("CIPHER: len/offset must be full bytes"); 1224c5788a10SHemant Agrawal return NULL; 1225c5788a10SHemant Agrawal } 1226c5788a10SHemant Agrawal 1227c5788a10SHemant Agrawal data_len = data_len >> 3; 1228c5788a10SHemant Agrawal data_offset = data_offset >> 3; 1229c5788a10SHemant Agrawal } 1230c3e85bdcSAkhil Goyal 1231f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, 4); 1232c3e85bdcSAkhil Goyal if (!ctx) 1233c3e85bdcSAkhil Goyal return NULL; 1234c3e85bdcSAkhil Goyal 1235c3e85bdcSAkhil Goyal cf = &ctx->job; 1236c3e85bdcSAkhil Goyal ctx->op = op; 1237a389434eSAlok Makhariya 1238bfa9a8a4SThomas Monjalon src_start_addr = rte_pktmbuf_iova(sym->m_src); 1239a389434eSAlok Makhariya 1240a389434eSAlok Makhariya if (sym->m_dst) 1241bfa9a8a4SThomas Monjalon dst_start_addr = rte_pktmbuf_iova(sym->m_dst); 1242a389434eSAlok Makhariya else 1243a389434eSAlok Makhariya dst_start_addr = src_start_addr; 1244c3e85bdcSAkhil Goyal 1245c3e85bdcSAkhil Goyal /* output */ 1246c3e85bdcSAkhil Goyal sg = &cf->sg[0]; 1247c5788a10SHemant Agrawal qm_sg_entry_set64(sg, dst_start_addr + data_offset); 1248c5788a10SHemant Agrawal sg->length = data_len + ses->iv.length; 1249c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1250c3e85bdcSAkhil Goyal 1251c3e85bdcSAkhil Goyal /* input */ 1252c3e85bdcSAkhil Goyal sg = &cf->sg[1]; 1253c3e85bdcSAkhil Goyal 1254c3e85bdcSAkhil Goyal /* need to extend the input to a compound frame */ 1255c3e85bdcSAkhil Goyal sg->extension = 1; 1256c3e85bdcSAkhil Goyal sg->final = 1; 1257c5788a10SHemant Agrawal sg->length = data_len + ses->iv.length; 1258ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(&cf->sg[2])); 1259c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1260c3e85bdcSAkhil Goyal 1261c3e85bdcSAkhil Goyal sg = &cf->sg[2]; 1262ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1263c3e85bdcSAkhil Goyal sg->length = ses->iv.length; 1264c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1265c3e85bdcSAkhil Goyal 1266c3e85bdcSAkhil Goyal sg++; 1267c5788a10SHemant Agrawal qm_sg_entry_set64(sg, src_start_addr + data_offset); 1268c5788a10SHemant Agrawal sg->length = data_len; 1269c3e85bdcSAkhil Goyal sg->final = 1; 1270c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1271c3e85bdcSAkhil Goyal 1272c3e85bdcSAkhil Goyal return cf; 1273c3e85bdcSAkhil Goyal } 1274c3e85bdcSAkhil Goyal 1275c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job * 1276a74af788SAkhil Goyal build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses) 1277a74af788SAkhil Goyal { 1278a74af788SAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1279a74af788SAkhil Goyal struct dpaa_sec_job *cf; 1280a74af788SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1281a74af788SAkhil Goyal struct qm_sg_entry *sg, *out_sg, *in_sg; 1282a74af788SAkhil Goyal struct rte_mbuf *mbuf; 1283a74af788SAkhil Goyal uint8_t req_segs; 1284a74af788SAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1285a74af788SAkhil Goyal ses->iv.offset); 1286a74af788SAkhil Goyal 1287a74af788SAkhil Goyal if (sym->m_dst) { 1288a74af788SAkhil Goyal mbuf = sym->m_dst; 1289a74af788SAkhil Goyal req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4; 1290a74af788SAkhil Goyal } else { 1291a74af788SAkhil Goyal mbuf = sym->m_src; 1292a74af788SAkhil Goyal req_segs = mbuf->nb_segs * 2 + 4; 1293a74af788SAkhil Goyal } 1294a74af788SAkhil Goyal 1295a74af788SAkhil Goyal if (ses->auth_only_len) 1296a74af788SAkhil Goyal req_segs++; 1297a74af788SAkhil Goyal 1298f7a5752eSHemant Agrawal if (mbuf->nb_segs > MAX_SG_ENTRIES) { 1299f163231eSHemant Agrawal DPAA_SEC_DP_ERR("AEAD: Max sec segs supported is %d", 1300a74af788SAkhil Goyal MAX_SG_ENTRIES); 1301a74af788SAkhil Goyal return NULL; 1302a74af788SAkhil Goyal } 1303a74af788SAkhil Goyal 1304f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, req_segs); 1305a74af788SAkhil Goyal if (!ctx) 1306a74af788SAkhil Goyal return NULL; 1307a74af788SAkhil Goyal 1308a74af788SAkhil Goyal cf = &ctx->job; 1309a74af788SAkhil Goyal ctx->op = op; 1310a74af788SAkhil Goyal 1311a74af788SAkhil Goyal rte_prefetch0(cf->sg); 1312a74af788SAkhil Goyal 1313a74af788SAkhil Goyal /* output */ 1314a74af788SAkhil Goyal out_sg = &cf->sg[0]; 1315a74af788SAkhil Goyal out_sg->extension = 1; 1316a74af788SAkhil Goyal if (is_encode(ses)) 13177a4a6da4SVakul Garg out_sg->length = sym->aead.data.length + ses->digest_length; 1318a74af788SAkhil Goyal else 13197a4a6da4SVakul Garg out_sg->length = sym->aead.data.length; 1320a74af788SAkhil Goyal 1321a74af788SAkhil Goyal /* output sg entries */ 1322a74af788SAkhil Goyal sg = &cf->sg[2]; 1323ec861560SGagandeep Singh qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg)); 1324a74af788SAkhil Goyal cpu_to_hw_sg(out_sg); 1325a74af788SAkhil Goyal 1326a74af788SAkhil Goyal /* 1st seg */ 1327ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 13287a4a6da4SVakul Garg sg->length = mbuf->data_len - sym->aead.data.offset; 13297a4a6da4SVakul Garg sg->offset = sym->aead.data.offset; 1330a74af788SAkhil Goyal 1331a74af788SAkhil Goyal /* Successive segs */ 1332a74af788SAkhil Goyal mbuf = mbuf->next; 1333a74af788SAkhil Goyal while (mbuf) { 1334a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1335a74af788SAkhil Goyal sg++; 1336ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1337a74af788SAkhil Goyal sg->length = mbuf->data_len; 1338a74af788SAkhil Goyal mbuf = mbuf->next; 1339a74af788SAkhil Goyal } 1340a74af788SAkhil Goyal sg->length -= ses->digest_length; 1341a74af788SAkhil Goyal 1342a74af788SAkhil Goyal if (is_encode(ses)) { 1343a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1344a74af788SAkhil Goyal /* set auth output */ 1345a74af788SAkhil Goyal sg++; 1346a74af788SAkhil Goyal qm_sg_entry_set64(sg, sym->aead.digest.phys_addr); 1347a74af788SAkhil Goyal sg->length = ses->digest_length; 1348a74af788SAkhil Goyal } 1349a74af788SAkhil Goyal sg->final = 1; 1350a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1351a74af788SAkhil Goyal 1352a74af788SAkhil Goyal /* input */ 1353a74af788SAkhil Goyal mbuf = sym->m_src; 1354a74af788SAkhil Goyal in_sg = &cf->sg[1]; 1355a74af788SAkhil Goyal in_sg->extension = 1; 1356a74af788SAkhil Goyal in_sg->final = 1; 1357a74af788SAkhil Goyal if (is_encode(ses)) 1358a74af788SAkhil Goyal in_sg->length = ses->iv.length + sym->aead.data.length 1359a74af788SAkhil Goyal + ses->auth_only_len; 1360a74af788SAkhil Goyal else 1361a74af788SAkhil Goyal in_sg->length = ses->iv.length + sym->aead.data.length 1362a74af788SAkhil Goyal + ses->auth_only_len + ses->digest_length; 1363a74af788SAkhil Goyal 1364a74af788SAkhil Goyal /* input sg entries */ 1365a74af788SAkhil Goyal sg++; 1366ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg)); 1367a74af788SAkhil Goyal cpu_to_hw_sg(in_sg); 1368a74af788SAkhil Goyal 1369a74af788SAkhil Goyal /* 1st seg IV */ 1370ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1371a74af788SAkhil Goyal sg->length = ses->iv.length; 1372a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1373a74af788SAkhil Goyal 1374a74af788SAkhil Goyal /* 2nd seg auth only */ 1375a74af788SAkhil Goyal if (ses->auth_only_len) { 1376a74af788SAkhil Goyal sg++; 1377ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(sym->aead.aad.data)); 1378a74af788SAkhil Goyal sg->length = ses->auth_only_len; 1379a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1380a74af788SAkhil Goyal } 1381a74af788SAkhil Goyal 1382a74af788SAkhil Goyal /* 3rd seg */ 1383a74af788SAkhil Goyal sg++; 1384ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1385a74af788SAkhil Goyal sg->length = mbuf->data_len - sym->aead.data.offset; 1386a74af788SAkhil Goyal sg->offset = sym->aead.data.offset; 1387a74af788SAkhil Goyal 1388a74af788SAkhil Goyal /* Successive segs */ 1389a74af788SAkhil Goyal mbuf = mbuf->next; 1390a74af788SAkhil Goyal while (mbuf) { 1391a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1392a74af788SAkhil Goyal sg++; 1393ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1394a74af788SAkhil Goyal sg->length = mbuf->data_len; 1395a74af788SAkhil Goyal mbuf = mbuf->next; 1396a74af788SAkhil Goyal } 1397a74af788SAkhil Goyal 1398a74af788SAkhil Goyal if (is_decode(ses)) { 1399a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1400a74af788SAkhil Goyal sg++; 1401a74af788SAkhil Goyal memcpy(ctx->digest, sym->aead.digest.data, 1402a74af788SAkhil Goyal ses->digest_length); 1403ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest)); 1404a74af788SAkhil Goyal sg->length = ses->digest_length; 1405a74af788SAkhil Goyal } 1406a74af788SAkhil Goyal sg->final = 1; 1407a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1408a74af788SAkhil Goyal 1409a74af788SAkhil Goyal return cf; 1410a74af788SAkhil Goyal } 1411a74af788SAkhil Goyal 1412a74af788SAkhil Goyal static inline struct dpaa_sec_job * 1413c3e85bdcSAkhil Goyal build_cipher_auth_gcm(struct rte_crypto_op *op, dpaa_sec_session *ses) 1414c3e85bdcSAkhil Goyal { 1415c3e85bdcSAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1416c3e85bdcSAkhil Goyal struct dpaa_sec_job *cf; 1417c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1418c3e85bdcSAkhil Goyal struct qm_sg_entry *sg; 1419c3e85bdcSAkhil Goyal uint32_t length = 0; 1420c4509373SSantosh Shukla rte_iova_t src_start_addr, dst_start_addr; 1421c3e85bdcSAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1422c3e85bdcSAkhil Goyal ses->iv.offset); 1423c3e85bdcSAkhil Goyal 1424116ff44aSHemant Agrawal src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off; 1425a389434eSAlok Makhariya 1426a389434eSAlok Makhariya if (sym->m_dst) 1427116ff44aSHemant Agrawal dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off; 1428a389434eSAlok Makhariya else 1429a389434eSAlok Makhariya dst_start_addr = src_start_addr; 1430c3e85bdcSAkhil Goyal 1431f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, 7); 1432c3e85bdcSAkhil Goyal if (!ctx) 1433c3e85bdcSAkhil Goyal return NULL; 1434c3e85bdcSAkhil Goyal 1435c3e85bdcSAkhil Goyal cf = &ctx->job; 1436c3e85bdcSAkhil Goyal ctx->op = op; 1437c3e85bdcSAkhil Goyal 1438c3e85bdcSAkhil Goyal /* input */ 1439c3e85bdcSAkhil Goyal rte_prefetch0(cf->sg); 1440c3e85bdcSAkhil Goyal sg = &cf->sg[2]; 1441ec861560SGagandeep Singh qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg)); 1442c3e85bdcSAkhil Goyal if (is_encode(ses)) { 1443ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1444c3e85bdcSAkhil Goyal sg->length = ses->iv.length; 1445c3e85bdcSAkhil Goyal length += sg->length; 1446c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1447c3e85bdcSAkhil Goyal 1448c3e85bdcSAkhil Goyal sg++; 1449c3e85bdcSAkhil Goyal if (ses->auth_only_len) { 1450c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, 1451ec861560SGagandeep Singh rte_dpaa_mem_vtop(sym->aead.aad.data)); 1452c3e85bdcSAkhil Goyal sg->length = ses->auth_only_len; 1453c3e85bdcSAkhil Goyal length += sg->length; 1454c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1455c3e85bdcSAkhil Goyal sg++; 1456c3e85bdcSAkhil Goyal } 1457a389434eSAlok Makhariya qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset); 1458c3e85bdcSAkhil Goyal sg->length = sym->aead.data.length; 1459c3e85bdcSAkhil Goyal length += sg->length; 1460c3e85bdcSAkhil Goyal sg->final = 1; 1461c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1462c3e85bdcSAkhil Goyal } else { 1463ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1464c3e85bdcSAkhil Goyal sg->length = ses->iv.length; 1465c3e85bdcSAkhil Goyal length += sg->length; 1466c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1467c3e85bdcSAkhil Goyal 1468c3e85bdcSAkhil Goyal sg++; 1469c3e85bdcSAkhil Goyal if (ses->auth_only_len) { 1470c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, 1471ec861560SGagandeep Singh rte_dpaa_mem_vtop(sym->aead.aad.data)); 1472c3e85bdcSAkhil Goyal sg->length = ses->auth_only_len; 1473c3e85bdcSAkhil Goyal length += sg->length; 1474c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1475c3e85bdcSAkhil Goyal sg++; 1476c3e85bdcSAkhil Goyal } 1477a389434eSAlok Makhariya qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset); 1478c3e85bdcSAkhil Goyal sg->length = sym->aead.data.length; 1479c3e85bdcSAkhil Goyal length += sg->length; 1480c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1481c3e85bdcSAkhil Goyal 1482c3e85bdcSAkhil Goyal memcpy(ctx->digest, sym->aead.digest.data, 1483c3e85bdcSAkhil Goyal ses->digest_length); 1484c3e85bdcSAkhil Goyal sg++; 1485c3e85bdcSAkhil Goyal 1486ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest)); 1487c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1488c3e85bdcSAkhil Goyal length += sg->length; 1489c3e85bdcSAkhil Goyal sg->final = 1; 1490c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1491c3e85bdcSAkhil Goyal } 1492c3e85bdcSAkhil Goyal /* input compound frame */ 1493c3e85bdcSAkhil Goyal cf->sg[1].length = length; 1494c3e85bdcSAkhil Goyal cf->sg[1].extension = 1; 1495c3e85bdcSAkhil Goyal cf->sg[1].final = 1; 1496c3e85bdcSAkhil Goyal cpu_to_hw_sg(&cf->sg[1]); 1497c3e85bdcSAkhil Goyal 1498c3e85bdcSAkhil Goyal /* output */ 1499c3e85bdcSAkhil Goyal sg++; 1500ec861560SGagandeep Singh qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg)); 1501c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, 15027a4a6da4SVakul Garg dst_start_addr + sym->aead.data.offset); 15037a4a6da4SVakul Garg sg->length = sym->aead.data.length; 1504c3e85bdcSAkhil Goyal length = sg->length; 1505c3e85bdcSAkhil Goyal if (is_encode(ses)) { 1506c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1507c3e85bdcSAkhil Goyal /* set auth output */ 1508c3e85bdcSAkhil Goyal sg++; 1509c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, sym->aead.digest.phys_addr); 1510c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1511c3e85bdcSAkhil Goyal length += sg->length; 1512c3e85bdcSAkhil Goyal } 1513c3e85bdcSAkhil Goyal sg->final = 1; 1514c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1515c3e85bdcSAkhil Goyal 1516c3e85bdcSAkhil Goyal /* output compound frame */ 1517c3e85bdcSAkhil Goyal cf->sg[0].length = length; 1518c3e85bdcSAkhil Goyal cf->sg[0].extension = 1; 1519c3e85bdcSAkhil Goyal cpu_to_hw_sg(&cf->sg[0]); 1520c3e85bdcSAkhil Goyal 1521c3e85bdcSAkhil Goyal return cf; 1522c3e85bdcSAkhil Goyal } 1523c3e85bdcSAkhil Goyal 1524c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job * 1525a74af788SAkhil Goyal build_cipher_auth_sg(struct rte_crypto_op *op, dpaa_sec_session *ses) 1526a74af788SAkhil Goyal { 1527a74af788SAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1528a74af788SAkhil Goyal struct dpaa_sec_job *cf; 1529a74af788SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1530a74af788SAkhil Goyal struct qm_sg_entry *sg, *out_sg, *in_sg; 1531a74af788SAkhil Goyal struct rte_mbuf *mbuf; 1532a74af788SAkhil Goyal uint8_t req_segs; 1533a74af788SAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1534a74af788SAkhil Goyal ses->iv.offset); 1535a74af788SAkhil Goyal 1536a74af788SAkhil Goyal if (sym->m_dst) { 1537a74af788SAkhil Goyal mbuf = sym->m_dst; 1538a74af788SAkhil Goyal req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4; 1539a74af788SAkhil Goyal } else { 1540a74af788SAkhil Goyal mbuf = sym->m_src; 1541a74af788SAkhil Goyal req_segs = mbuf->nb_segs * 2 + 4; 1542a74af788SAkhil Goyal } 1543a74af788SAkhil Goyal 1544f7a5752eSHemant Agrawal if (mbuf->nb_segs > MAX_SG_ENTRIES) { 1545f163231eSHemant Agrawal DPAA_SEC_DP_ERR("Cipher-Auth: Max sec segs supported is %d", 1546a74af788SAkhil Goyal MAX_SG_ENTRIES); 1547a74af788SAkhil Goyal return NULL; 1548a74af788SAkhil Goyal } 1549a74af788SAkhil Goyal 1550f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, req_segs); 1551a74af788SAkhil Goyal if (!ctx) 1552a74af788SAkhil Goyal return NULL; 1553a74af788SAkhil Goyal 1554a74af788SAkhil Goyal cf = &ctx->job; 1555a74af788SAkhil Goyal ctx->op = op; 1556a74af788SAkhil Goyal 1557a74af788SAkhil Goyal rte_prefetch0(cf->sg); 1558a74af788SAkhil Goyal 1559a74af788SAkhil Goyal /* output */ 1560a74af788SAkhil Goyal out_sg = &cf->sg[0]; 1561a74af788SAkhil Goyal out_sg->extension = 1; 1562a74af788SAkhil Goyal if (is_encode(ses)) 1563a74af788SAkhil Goyal out_sg->length = sym->auth.data.length + ses->digest_length; 1564a74af788SAkhil Goyal else 1565a74af788SAkhil Goyal out_sg->length = sym->auth.data.length; 1566a74af788SAkhil Goyal 1567a74af788SAkhil Goyal /* output sg entries */ 1568a74af788SAkhil Goyal sg = &cf->sg[2]; 1569ec861560SGagandeep Singh qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg)); 1570a74af788SAkhil Goyal cpu_to_hw_sg(out_sg); 1571a74af788SAkhil Goyal 1572a74af788SAkhil Goyal /* 1st seg */ 1573ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1574a74af788SAkhil Goyal sg->length = mbuf->data_len - sym->auth.data.offset; 1575a74af788SAkhil Goyal sg->offset = sym->auth.data.offset; 1576a74af788SAkhil Goyal 1577a74af788SAkhil Goyal /* Successive segs */ 1578a74af788SAkhil Goyal mbuf = mbuf->next; 1579a74af788SAkhil Goyal while (mbuf) { 1580a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1581a74af788SAkhil Goyal sg++; 1582ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1583a74af788SAkhil Goyal sg->length = mbuf->data_len; 1584a74af788SAkhil Goyal mbuf = mbuf->next; 1585a74af788SAkhil Goyal } 1586a74af788SAkhil Goyal sg->length -= ses->digest_length; 1587a74af788SAkhil Goyal 1588a74af788SAkhil Goyal if (is_encode(ses)) { 1589a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1590a74af788SAkhil Goyal /* set auth output */ 1591a74af788SAkhil Goyal sg++; 1592a74af788SAkhil Goyal qm_sg_entry_set64(sg, sym->auth.digest.phys_addr); 1593a74af788SAkhil Goyal sg->length = ses->digest_length; 1594a74af788SAkhil Goyal } 1595a74af788SAkhil Goyal sg->final = 1; 1596a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1597a74af788SAkhil Goyal 1598a74af788SAkhil Goyal /* input */ 1599a74af788SAkhil Goyal mbuf = sym->m_src; 1600a74af788SAkhil Goyal in_sg = &cf->sg[1]; 1601a74af788SAkhil Goyal in_sg->extension = 1; 1602a74af788SAkhil Goyal in_sg->final = 1; 1603a74af788SAkhil Goyal if (is_encode(ses)) 1604a74af788SAkhil Goyal in_sg->length = ses->iv.length + sym->auth.data.length; 1605a74af788SAkhil Goyal else 1606a74af788SAkhil Goyal in_sg->length = ses->iv.length + sym->auth.data.length 1607a74af788SAkhil Goyal + ses->digest_length; 1608a74af788SAkhil Goyal 1609a74af788SAkhil Goyal /* input sg entries */ 1610a74af788SAkhil Goyal sg++; 1611ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg)); 1612a74af788SAkhil Goyal cpu_to_hw_sg(in_sg); 1613a74af788SAkhil Goyal 1614a74af788SAkhil Goyal /* 1st seg IV */ 1615ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1616a74af788SAkhil Goyal sg->length = ses->iv.length; 1617a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1618a74af788SAkhil Goyal 1619a74af788SAkhil Goyal /* 2nd seg */ 1620a74af788SAkhil Goyal sg++; 1621ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1622a74af788SAkhil Goyal sg->length = mbuf->data_len - sym->auth.data.offset; 1623a74af788SAkhil Goyal sg->offset = sym->auth.data.offset; 1624a74af788SAkhil Goyal 1625a74af788SAkhil Goyal /* Successive segs */ 1626a74af788SAkhil Goyal mbuf = mbuf->next; 1627a74af788SAkhil Goyal while (mbuf) { 1628a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1629a74af788SAkhil Goyal sg++; 1630ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1631a74af788SAkhil Goyal sg->length = mbuf->data_len; 1632a74af788SAkhil Goyal mbuf = mbuf->next; 1633a74af788SAkhil Goyal } 1634a74af788SAkhil Goyal 1635a74af788SAkhil Goyal sg->length -= ses->digest_length; 1636a74af788SAkhil Goyal if (is_decode(ses)) { 1637a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1638a74af788SAkhil Goyal sg++; 1639a74af788SAkhil Goyal memcpy(ctx->digest, sym->auth.digest.data, 1640a74af788SAkhil Goyal ses->digest_length); 1641ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest)); 1642a74af788SAkhil Goyal sg->length = ses->digest_length; 1643a74af788SAkhil Goyal } 1644a74af788SAkhil Goyal sg->final = 1; 1645a74af788SAkhil Goyal cpu_to_hw_sg(sg); 1646a74af788SAkhil Goyal 1647a74af788SAkhil Goyal return cf; 1648a74af788SAkhil Goyal } 1649a74af788SAkhil Goyal 1650a74af788SAkhil Goyal static inline struct dpaa_sec_job * 1651c3e85bdcSAkhil Goyal build_cipher_auth(struct rte_crypto_op *op, dpaa_sec_session *ses) 1652c3e85bdcSAkhil Goyal { 1653c3e85bdcSAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1654c3e85bdcSAkhil Goyal struct dpaa_sec_job *cf; 1655c3e85bdcSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1656c3e85bdcSAkhil Goyal struct qm_sg_entry *sg; 1657c4509373SSantosh Shukla rte_iova_t src_start_addr, dst_start_addr; 1658c3e85bdcSAkhil Goyal uint32_t length = 0; 1659c3e85bdcSAkhil Goyal uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, 1660c3e85bdcSAkhil Goyal ses->iv.offset); 1661c3e85bdcSAkhil Goyal 1662455da545SSantosh Shukla src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off; 1663a389434eSAlok Makhariya if (sym->m_dst) 1664455da545SSantosh Shukla dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off; 1665a389434eSAlok Makhariya else 1666a389434eSAlok Makhariya dst_start_addr = src_start_addr; 1667c3e85bdcSAkhil Goyal 1668f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, 7); 1669c3e85bdcSAkhil Goyal if (!ctx) 1670c3e85bdcSAkhil Goyal return NULL; 1671c3e85bdcSAkhil Goyal 1672c3e85bdcSAkhil Goyal cf = &ctx->job; 1673c3e85bdcSAkhil Goyal ctx->op = op; 1674c3e85bdcSAkhil Goyal 1675c3e85bdcSAkhil Goyal /* input */ 1676c3e85bdcSAkhil Goyal rte_prefetch0(cf->sg); 1677c3e85bdcSAkhil Goyal sg = &cf->sg[2]; 1678ec861560SGagandeep Singh qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg)); 1679c3e85bdcSAkhil Goyal if (is_encode(ses)) { 1680ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1681c3e85bdcSAkhil Goyal sg->length = ses->iv.length; 1682c3e85bdcSAkhil Goyal length += sg->length; 1683c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1684c3e85bdcSAkhil Goyal 1685c3e85bdcSAkhil Goyal sg++; 1686a389434eSAlok Makhariya qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset); 1687c3e85bdcSAkhil Goyal sg->length = sym->auth.data.length; 1688c3e85bdcSAkhil Goyal length += sg->length; 1689c3e85bdcSAkhil Goyal sg->final = 1; 1690c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1691c3e85bdcSAkhil Goyal } else { 1692ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr)); 1693c3e85bdcSAkhil Goyal sg->length = ses->iv.length; 1694c3e85bdcSAkhil Goyal length += sg->length; 1695c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1696c3e85bdcSAkhil Goyal 1697c3e85bdcSAkhil Goyal sg++; 1698c3e85bdcSAkhil Goyal 1699a389434eSAlok Makhariya qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset); 1700c3e85bdcSAkhil Goyal sg->length = sym->auth.data.length; 1701c3e85bdcSAkhil Goyal length += sg->length; 1702c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1703c3e85bdcSAkhil Goyal 1704c3e85bdcSAkhil Goyal memcpy(ctx->digest, sym->auth.digest.data, 1705c3e85bdcSAkhil Goyal ses->digest_length); 1706c3e85bdcSAkhil Goyal sg++; 1707c3e85bdcSAkhil Goyal 1708ec861560SGagandeep Singh qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest)); 1709c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1710c3e85bdcSAkhil Goyal length += sg->length; 1711c3e85bdcSAkhil Goyal sg->final = 1; 1712c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1713c3e85bdcSAkhil Goyal } 1714c3e85bdcSAkhil Goyal /* input compound frame */ 1715c3e85bdcSAkhil Goyal cf->sg[1].length = length; 1716c3e85bdcSAkhil Goyal cf->sg[1].extension = 1; 1717c3e85bdcSAkhil Goyal cf->sg[1].final = 1; 1718c3e85bdcSAkhil Goyal cpu_to_hw_sg(&cf->sg[1]); 1719c3e85bdcSAkhil Goyal 1720c3e85bdcSAkhil Goyal /* output */ 1721c3e85bdcSAkhil Goyal sg++; 1722ec861560SGagandeep Singh qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg)); 1723a389434eSAlok Makhariya qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset); 1724c3e85bdcSAkhil Goyal sg->length = sym->cipher.data.length; 1725c3e85bdcSAkhil Goyal length = sg->length; 1726c3e85bdcSAkhil Goyal if (is_encode(ses)) { 1727c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1728c3e85bdcSAkhil Goyal /* set auth output */ 1729c3e85bdcSAkhil Goyal sg++; 1730c3e85bdcSAkhil Goyal qm_sg_entry_set64(sg, sym->auth.digest.phys_addr); 1731c3e85bdcSAkhil Goyal sg->length = ses->digest_length; 1732c3e85bdcSAkhil Goyal length += sg->length; 1733c3e85bdcSAkhil Goyal } 1734c3e85bdcSAkhil Goyal sg->final = 1; 1735c3e85bdcSAkhil Goyal cpu_to_hw_sg(sg); 1736c3e85bdcSAkhil Goyal 1737c3e85bdcSAkhil Goyal /* output compound frame */ 1738c3e85bdcSAkhil Goyal cf->sg[0].length = length; 1739c3e85bdcSAkhil Goyal cf->sg[0].extension = 1; 1740c3e85bdcSAkhil Goyal cpu_to_hw_sg(&cf->sg[0]); 1741c3e85bdcSAkhil Goyal 1742c3e85bdcSAkhil Goyal return cf; 1743c3e85bdcSAkhil Goyal } 1744c3e85bdcSAkhil Goyal 17451f14d500SAkhil Goyal static inline struct dpaa_sec_job * 17461f14d500SAkhil Goyal build_proto(struct rte_crypto_op *op, dpaa_sec_session *ses) 17471f14d500SAkhil Goyal { 17481f14d500SAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 17491f14d500SAkhil Goyal struct dpaa_sec_job *cf; 17501f14d500SAkhil Goyal struct dpaa_sec_op_ctx *ctx; 17511f14d500SAkhil Goyal struct qm_sg_entry *sg; 17521f14d500SAkhil Goyal phys_addr_t src_start_addr, dst_start_addr; 17531f14d500SAkhil Goyal 1754f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, 2); 17551f14d500SAkhil Goyal if (!ctx) 17561f14d500SAkhil Goyal return NULL; 17571f14d500SAkhil Goyal cf = &ctx->job; 17581f14d500SAkhil Goyal ctx->op = op; 17591f14d500SAkhil Goyal 1760ce627d63SThomas Monjalon src_start_addr = rte_pktmbuf_iova(sym->m_src); 17611f14d500SAkhil Goyal 17621f14d500SAkhil Goyal if (sym->m_dst) 1763ce627d63SThomas Monjalon dst_start_addr = rte_pktmbuf_iova(sym->m_dst); 17641f14d500SAkhil Goyal else 17651f14d500SAkhil Goyal dst_start_addr = src_start_addr; 17661f14d500SAkhil Goyal 17671f14d500SAkhil Goyal /* input */ 17681f14d500SAkhil Goyal sg = &cf->sg[1]; 17691f14d500SAkhil Goyal qm_sg_entry_set64(sg, src_start_addr); 17701f14d500SAkhil Goyal sg->length = sym->m_src->pkt_len; 17711f14d500SAkhil Goyal sg->final = 1; 17721f14d500SAkhil Goyal cpu_to_hw_sg(sg); 17731f14d500SAkhil Goyal 17741f14d500SAkhil Goyal sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK; 17751f14d500SAkhil Goyal /* output */ 17761f14d500SAkhil Goyal sg = &cf->sg[0]; 17771f14d500SAkhil Goyal qm_sg_entry_set64(sg, dst_start_addr); 17781f14d500SAkhil Goyal sg->length = sym->m_src->buf_len - sym->m_src->data_off; 17791f14d500SAkhil Goyal cpu_to_hw_sg(sg); 17801f14d500SAkhil Goyal 17811f14d500SAkhil Goyal return cf; 17821f14d500SAkhil Goyal } 17831f14d500SAkhil Goyal 1784fb5c100aSAkhil Goyal static inline struct dpaa_sec_job * 1785fb5c100aSAkhil Goyal build_proto_sg(struct rte_crypto_op *op, dpaa_sec_session *ses) 1786fb5c100aSAkhil Goyal { 1787fb5c100aSAkhil Goyal struct rte_crypto_sym_op *sym = op->sym; 1788fb5c100aSAkhil Goyal struct dpaa_sec_job *cf; 1789fb5c100aSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 1790fb5c100aSAkhil Goyal struct qm_sg_entry *sg, *out_sg, *in_sg; 1791fb5c100aSAkhil Goyal struct rte_mbuf *mbuf; 1792fb5c100aSAkhil Goyal uint8_t req_segs; 1793fb5c100aSAkhil Goyal uint32_t in_len = 0, out_len = 0; 1794fb5c100aSAkhil Goyal 1795fb5c100aSAkhil Goyal if (sym->m_dst) 1796fb5c100aSAkhil Goyal mbuf = sym->m_dst; 1797fb5c100aSAkhil Goyal else 1798fb5c100aSAkhil Goyal mbuf = sym->m_src; 1799fb5c100aSAkhil Goyal 1800fb5c100aSAkhil Goyal req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 2; 1801f7a5752eSHemant Agrawal if (mbuf->nb_segs > MAX_SG_ENTRIES) { 1802fb5c100aSAkhil Goyal DPAA_SEC_DP_ERR("Proto: Max sec segs supported is %d", 1803fb5c100aSAkhil Goyal MAX_SG_ENTRIES); 1804fb5c100aSAkhil Goyal return NULL; 1805fb5c100aSAkhil Goyal } 1806fb5c100aSAkhil Goyal 1807f7a5752eSHemant Agrawal ctx = dpaa_sec_alloc_ctx(ses, req_segs); 1808fb5c100aSAkhil Goyal if (!ctx) 1809fb5c100aSAkhil Goyal return NULL; 1810fb5c100aSAkhil Goyal cf = &ctx->job; 1811fb5c100aSAkhil Goyal ctx->op = op; 1812fb5c100aSAkhil Goyal /* output */ 1813fb5c100aSAkhil Goyal out_sg = &cf->sg[0]; 1814fb5c100aSAkhil Goyal out_sg->extension = 1; 1815ec861560SGagandeep Singh qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2])); 1816fb5c100aSAkhil Goyal 1817fb5c100aSAkhil Goyal /* 1st seg */ 1818fb5c100aSAkhil Goyal sg = &cf->sg[2]; 1819ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1820fb5c100aSAkhil Goyal sg->offset = 0; 1821fb5c100aSAkhil Goyal 1822fb5c100aSAkhil Goyal /* Successive segs */ 1823fb5c100aSAkhil Goyal while (mbuf->next) { 1824fb5c100aSAkhil Goyal sg->length = mbuf->data_len; 1825fb5c100aSAkhil Goyal out_len += sg->length; 1826fb5c100aSAkhil Goyal mbuf = mbuf->next; 1827fb5c100aSAkhil Goyal cpu_to_hw_sg(sg); 1828fb5c100aSAkhil Goyal sg++; 1829ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1830fb5c100aSAkhil Goyal sg->offset = 0; 1831fb5c100aSAkhil Goyal } 1832fb5c100aSAkhil Goyal sg->length = mbuf->buf_len - mbuf->data_off; 1833fb5c100aSAkhil Goyal out_len += sg->length; 1834fb5c100aSAkhil Goyal sg->final = 1; 1835fb5c100aSAkhil Goyal cpu_to_hw_sg(sg); 1836fb5c100aSAkhil Goyal 1837fb5c100aSAkhil Goyal out_sg->length = out_len; 1838fb5c100aSAkhil Goyal cpu_to_hw_sg(out_sg); 1839fb5c100aSAkhil Goyal 1840fb5c100aSAkhil Goyal /* input */ 1841fb5c100aSAkhil Goyal mbuf = sym->m_src; 1842fb5c100aSAkhil Goyal in_sg = &cf->sg[1]; 1843fb5c100aSAkhil Goyal in_sg->extension = 1; 1844fb5c100aSAkhil Goyal in_sg->final = 1; 1845fb5c100aSAkhil Goyal in_len = mbuf->data_len; 1846fb5c100aSAkhil Goyal 1847fb5c100aSAkhil Goyal sg++; 1848ec861560SGagandeep Singh qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg)); 1849fb5c100aSAkhil Goyal 1850fb5c100aSAkhil Goyal /* 1st seg */ 1851ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1852fb5c100aSAkhil Goyal sg->length = mbuf->data_len; 1853fb5c100aSAkhil Goyal sg->offset = 0; 1854fb5c100aSAkhil Goyal 1855fb5c100aSAkhil Goyal /* Successive segs */ 1856fb5c100aSAkhil Goyal mbuf = mbuf->next; 1857fb5c100aSAkhil Goyal while (mbuf) { 1858fb5c100aSAkhil Goyal cpu_to_hw_sg(sg); 1859fb5c100aSAkhil Goyal sg++; 1860ce627d63SThomas Monjalon qm_sg_entry_set64(sg, rte_pktmbuf_iova(mbuf)); 1861fb5c100aSAkhil Goyal sg->length = mbuf->data_len; 1862fb5c100aSAkhil Goyal sg->offset = 0; 1863fb5c100aSAkhil Goyal in_len += sg->length; 1864fb5c100aSAkhil Goyal mbuf = mbuf->next; 1865fb5c100aSAkhil Goyal } 1866fb5c100aSAkhil Goyal sg->final = 1; 1867fb5c100aSAkhil Goyal cpu_to_hw_sg(sg); 1868fb5c100aSAkhil Goyal 1869fb5c100aSAkhil Goyal in_sg->length = in_len; 1870fb5c100aSAkhil Goyal cpu_to_hw_sg(in_sg); 1871fb5c100aSAkhil Goyal 1872fb5c100aSAkhil Goyal sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK; 1873fb5c100aSAkhil Goyal 1874fb5c100aSAkhil Goyal return cf; 1875fb5c100aSAkhil Goyal } 1876fb5c100aSAkhil Goyal 18779a984458SAkhil Goyal static uint16_t 18789a984458SAkhil Goyal dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops, 18799a984458SAkhil Goyal uint16_t nb_ops) 1880c3e85bdcSAkhil Goyal { 18819a984458SAkhil Goyal /* Function to transmit the frames to given device and queuepair */ 18829a984458SAkhil Goyal uint32_t loop; 18839a984458SAkhil Goyal struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp; 18849a984458SAkhil Goyal uint16_t num_tx = 0; 18859a984458SAkhil Goyal struct qm_fd fds[DPAA_SEC_BURST], *fd; 18869a984458SAkhil Goyal uint32_t frames_to_send; 18879a984458SAkhil Goyal struct rte_crypto_op *op; 1888c3e85bdcSAkhil Goyal struct dpaa_sec_job *cf; 1889c3e85bdcSAkhil Goyal dpaa_sec_session *ses; 18903394ed47SVakul Garg uint16_t auth_hdr_len, auth_tail_len; 18913394ed47SVakul Garg uint32_t index, flags[DPAA_SEC_BURST] = {0}; 18929a984458SAkhil Goyal struct qman_fq *inq[DPAA_SEC_BURST]; 1893c3e85bdcSAkhil Goyal 189422629f05SHemant Agrawal if (unlikely(!DPAA_PER_LCORE_PORTAL)) { 189522629f05SHemant Agrawal if (rte_dpaa_portal_init((void *)0)) { 189622629f05SHemant Agrawal DPAA_SEC_ERR("Failure in affining portal"); 189722629f05SHemant Agrawal return 0; 189822629f05SHemant Agrawal } 189922629f05SHemant Agrawal } 190022629f05SHemant Agrawal 19019a984458SAkhil Goyal while (nb_ops) { 19029a984458SAkhil Goyal frames_to_send = (nb_ops > DPAA_SEC_BURST) ? 19039a984458SAkhil Goyal DPAA_SEC_BURST : nb_ops; 19049a984458SAkhil Goyal for (loop = 0; loop < frames_to_send; loop++) { 19059a984458SAkhil Goyal op = *(ops++); 1906c9a1c2e5SDavid Marchand if (*dpaa_seqn(op->sym->m_src) != 0) { 1907c9a1c2e5SDavid Marchand index = *dpaa_seqn(op->sym->m_src) - 1; 1908fe3688baSAkhil Goyal if (DPAA_PER_LCORE_DQRR_HELD & (1 << index)) { 1909fe3688baSAkhil Goyal /* QM_EQCR_DCA_IDXMASK = 0x0f */ 1910fe3688baSAkhil Goyal flags[loop] = ((index & 0x0f) << 8); 1911fe3688baSAkhil Goyal flags[loop] |= QMAN_ENQUEUE_FLAG_DCA; 1912fe3688baSAkhil Goyal DPAA_PER_LCORE_DQRR_SIZE--; 1913fe3688baSAkhil Goyal DPAA_PER_LCORE_DQRR_HELD &= 1914fe3688baSAkhil Goyal ~(1 << index); 1915fe3688baSAkhil Goyal } 1916fe3688baSAkhil Goyal } 1917fe3688baSAkhil Goyal 19189a984458SAkhil Goyal switch (op->sess_type) { 19199a984458SAkhil Goyal case RTE_CRYPTO_OP_WITH_SESSION: 19202a440d6aSAkhil Goyal ses = CRYPTODEV_GET_SYM_SESS_PRIV(op->sym->session); 19219a984458SAkhil Goyal break; 19229a984458SAkhil Goyal case RTE_CRYPTO_OP_SECURITY_SESSION: 19232973dbf9SAkhil Goyal ses = SECURITY_GET_SESS_PRIV(op->sym->session); 19249a984458SAkhil Goyal break; 19259a984458SAkhil Goyal default: 1926f163231eSHemant Agrawal DPAA_SEC_DP_ERR( 19279a984458SAkhil Goyal "sessionless crypto op not supported"); 19289a984458SAkhil Goyal frames_to_send = loop; 19299a984458SAkhil Goyal nb_ops = loop; 19309a984458SAkhil Goyal goto send_pkts; 19319a984458SAkhil Goyal } 1932e1e52232SHemant Agrawal 1933e1e52232SHemant Agrawal if (!ses) { 1934e1e52232SHemant Agrawal DPAA_SEC_DP_ERR("session not available"); 1935e1e52232SHemant Agrawal frames_to_send = loop; 1936e1e52232SHemant Agrawal nb_ops = loop; 1937e1e52232SHemant Agrawal goto send_pkts; 1938e1e52232SHemant Agrawal } 1939e1e52232SHemant Agrawal 19404e694fe5SAkhil Goyal if (unlikely(!ses->qp[rte_lcore_id() % MAX_DPAA_CORES])) { 19419a984458SAkhil Goyal if (dpaa_sec_attach_sess_q(qp, ses)) { 19429a984458SAkhil Goyal frames_to_send = loop; 19439a984458SAkhil Goyal nb_ops = loop; 19449a984458SAkhil Goyal goto send_pkts; 19459a984458SAkhil Goyal } 19464e694fe5SAkhil Goyal } else if (unlikely(ses->qp[rte_lcore_id() % 19474e694fe5SAkhil Goyal MAX_DPAA_CORES] != qp)) { 19489198b2c2SAkhil Goyal DPAA_SEC_DP_ERR("Old:sess->qp = %p" 1949*f665790aSDavid Marchand " New qp = %p", 19504e694fe5SAkhil Goyal ses->qp[rte_lcore_id() % 19514e694fe5SAkhil Goyal MAX_DPAA_CORES], qp); 19529198b2c2SAkhil Goyal frames_to_send = loop; 19539198b2c2SAkhil Goyal nb_ops = loop; 19549198b2c2SAkhil Goyal goto send_pkts; 1955c3e85bdcSAkhil Goyal } 1956c3e85bdcSAkhil Goyal 19573394ed47SVakul Garg auth_hdr_len = op->sym->auth.data.length - 19589a984458SAkhil Goyal op->sym->cipher.data.length; 19593394ed47SVakul Garg auth_tail_len = 0; 19603394ed47SVakul Garg 1961fb5c100aSAkhil Goyal if (rte_pktmbuf_is_contiguous(op->sym->m_src) && 1962fb5c100aSAkhil Goyal ((op->sym->m_dst == NULL) || 1963fb5c100aSAkhil Goyal rte_pktmbuf_is_contiguous(op->sym->m_dst))) { 19648524b44eSHemant Agrawal switch (ses->ctxt) { 19658524b44eSHemant Agrawal case DPAA_SEC_PDCP: 19668524b44eSHemant Agrawal case DPAA_SEC_IPSEC: 196705b12700SHemant Agrawal cf = build_proto(op, ses); 19688524b44eSHemant Agrawal break; 19698524b44eSHemant Agrawal case DPAA_SEC_AUTH: 1970c3e85bdcSAkhil Goyal cf = build_auth_only(op, ses); 19718524b44eSHemant Agrawal break; 19728524b44eSHemant Agrawal case DPAA_SEC_CIPHER: 1973c3e85bdcSAkhil Goyal cf = build_cipher_only(op, ses); 19748524b44eSHemant Agrawal break; 19758524b44eSHemant Agrawal case DPAA_SEC_AEAD: 1976c3e85bdcSAkhil Goyal cf = build_cipher_auth_gcm(op, ses); 19773394ed47SVakul Garg auth_hdr_len = ses->auth_only_len; 19788524b44eSHemant Agrawal break; 19798524b44eSHemant Agrawal case DPAA_SEC_CIPHER_HASH: 19803394ed47SVakul Garg auth_hdr_len = 19813394ed47SVakul Garg op->sym->cipher.data.offset 19823394ed47SVakul Garg - op->sym->auth.data.offset; 19833394ed47SVakul Garg auth_tail_len = 19843394ed47SVakul Garg op->sym->auth.data.length 19853394ed47SVakul Garg - op->sym->cipher.data.length 19863394ed47SVakul Garg - auth_hdr_len; 1987c3e85bdcSAkhil Goyal cf = build_cipher_auth(op, ses); 19888524b44eSHemant Agrawal break; 19898524b44eSHemant Agrawal default: 1990f163231eSHemant Agrawal DPAA_SEC_DP_ERR("not supported ops"); 19919a984458SAkhil Goyal frames_to_send = loop; 19929a984458SAkhil Goyal nb_ops = loop; 19939a984458SAkhil Goyal goto send_pkts; 1994c3e85bdcSAkhil Goyal } 1995a74af788SAkhil Goyal } else { 19968524b44eSHemant Agrawal switch (ses->ctxt) { 19978524b44eSHemant Agrawal case DPAA_SEC_PDCP: 19988524b44eSHemant Agrawal case DPAA_SEC_IPSEC: 1999fb5c100aSAkhil Goyal cf = build_proto_sg(op, ses); 20008524b44eSHemant Agrawal break; 20018524b44eSHemant Agrawal case DPAA_SEC_AUTH: 2002a74af788SAkhil Goyal cf = build_auth_only_sg(op, ses); 20038524b44eSHemant Agrawal break; 20048524b44eSHemant Agrawal case DPAA_SEC_CIPHER: 2005a74af788SAkhil Goyal cf = build_cipher_only_sg(op, ses); 20068524b44eSHemant Agrawal break; 20078524b44eSHemant Agrawal case DPAA_SEC_AEAD: 2008a74af788SAkhil Goyal cf = build_cipher_auth_gcm_sg(op, ses); 20093394ed47SVakul Garg auth_hdr_len = ses->auth_only_len; 20108524b44eSHemant Agrawal break; 20118524b44eSHemant Agrawal case DPAA_SEC_CIPHER_HASH: 20123394ed47SVakul Garg auth_hdr_len = 20133394ed47SVakul Garg op->sym->cipher.data.offset 20143394ed47SVakul Garg - op->sym->auth.data.offset; 20153394ed47SVakul Garg auth_tail_len = 20163394ed47SVakul Garg op->sym->auth.data.length 20173394ed47SVakul Garg - op->sym->cipher.data.length 20183394ed47SVakul Garg - auth_hdr_len; 2019a74af788SAkhil Goyal cf = build_cipher_auth_sg(op, ses); 20208524b44eSHemant Agrawal break; 20218524b44eSHemant Agrawal default: 2022f163231eSHemant Agrawal DPAA_SEC_DP_ERR("not supported ops"); 2023a74af788SAkhil Goyal frames_to_send = loop; 2024a74af788SAkhil Goyal nb_ops = loop; 2025a74af788SAkhil Goyal goto send_pkts; 2026a74af788SAkhil Goyal } 2027a74af788SAkhil Goyal } 20289a984458SAkhil Goyal if (unlikely(!cf)) { 20299a984458SAkhil Goyal frames_to_send = loop; 20309a984458SAkhil Goyal nb_ops = loop; 20319a984458SAkhil Goyal goto send_pkts; 20329a984458SAkhil Goyal } 2033c3e85bdcSAkhil Goyal 20349a984458SAkhil Goyal fd = &fds[loop]; 20354e694fe5SAkhil Goyal inq[loop] = ses->inq[rte_lcore_id() % MAX_DPAA_CORES]; 20369a984458SAkhil Goyal fd->opaque_addr = 0; 20379a984458SAkhil Goyal fd->cmd = 0; 2038ec861560SGagandeep Singh qm_fd_addr_set64(fd, rte_dpaa_mem_vtop(cf->sg)); 20399a984458SAkhil Goyal fd->_format1 = qm_fd_compound; 20409a984458SAkhil Goyal fd->length29 = 2 * sizeof(struct qm_sg_entry); 20413394ed47SVakul Garg 20429a984458SAkhil Goyal /* Auth_only_len is set as 0 in descriptor and it is 20439a984458SAkhil Goyal * overwritten here in the fd.cmd which will update 20449a984458SAkhil Goyal * the DPOVRD reg. 2045c3e85bdcSAkhil Goyal */ 20463394ed47SVakul Garg if (auth_hdr_len || auth_tail_len) { 20473394ed47SVakul Garg fd->cmd = 0x80000000; 20483394ed47SVakul Garg fd->cmd |= 20493394ed47SVakul Garg ((auth_tail_len << 16) | auth_hdr_len); 20503394ed47SVakul Garg } 2051c3e85bdcSAkhil Goyal 20526a0c9d36SAkhil Goyal /* In case of PDCP, per packet HFN is stored in 20536a0c9d36SAkhil Goyal * mbuf priv after sym_op. 20546a0c9d36SAkhil Goyal */ 20558524b44eSHemant Agrawal if ((ses->ctxt == DPAA_SEC_PDCP) && ses->pdcp.hfn_ovd) { 20566a0c9d36SAkhil Goyal fd->cmd = 0x80000000 | 20576a0c9d36SAkhil Goyal *((uint32_t *)((uint8_t *)op + 20586a0c9d36SAkhil Goyal ses->pdcp.hfn_ovd_offset)); 2059*f665790aSDavid Marchand DPAA_SEC_DP_DEBUG("Per packet HFN: %x, ovd:%u", 20606a0c9d36SAkhil Goyal *((uint32_t *)((uint8_t *)op + 20616a0c9d36SAkhil Goyal ses->pdcp.hfn_ovd_offset)), 20628524b44eSHemant Agrawal ses->pdcp.hfn_ovd); 20636a0c9d36SAkhil Goyal } 20649a984458SAkhil Goyal } 20659a984458SAkhil Goyal send_pkts: 20669a984458SAkhil Goyal loop = 0; 20679a984458SAkhil Goyal while (loop < frames_to_send) { 20689a984458SAkhil Goyal loop += qman_enqueue_multi_fq(&inq[loop], &fds[loop], 2069fe3688baSAkhil Goyal &flags[loop], frames_to_send - loop); 20709a984458SAkhil Goyal } 20719a984458SAkhil Goyal nb_ops -= frames_to_send; 20729a984458SAkhil Goyal num_tx += frames_to_send; 2073c3e85bdcSAkhil Goyal } 2074c3e85bdcSAkhil Goyal 2075c3e85bdcSAkhil Goyal dpaa_qp->tx_pkts += num_tx; 2076c3e85bdcSAkhil Goyal dpaa_qp->tx_errs += nb_ops - num_tx; 2077c3e85bdcSAkhil Goyal 2078c3e85bdcSAkhil Goyal return num_tx; 2079c3e85bdcSAkhil Goyal } 2080c3e85bdcSAkhil Goyal 2081c3e85bdcSAkhil Goyal static uint16_t 2082c3e85bdcSAkhil Goyal dpaa_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops, 2083c3e85bdcSAkhil Goyal uint16_t nb_ops) 2084c3e85bdcSAkhil Goyal { 2085c3e85bdcSAkhil Goyal uint16_t num_rx; 2086c3e85bdcSAkhil Goyal struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp; 2087c3e85bdcSAkhil Goyal 208822629f05SHemant Agrawal if (unlikely(!DPAA_PER_LCORE_PORTAL)) { 208922629f05SHemant Agrawal if (rte_dpaa_portal_init((void *)0)) { 209022629f05SHemant Agrawal DPAA_SEC_ERR("Failure in affining portal"); 209122629f05SHemant Agrawal return 0; 209222629f05SHemant Agrawal } 209322629f05SHemant Agrawal } 209422629f05SHemant Agrawal 2095c3e85bdcSAkhil Goyal num_rx = dpaa_sec_deq(dpaa_qp, ops, nb_ops); 2096c3e85bdcSAkhil Goyal 2097c3e85bdcSAkhil Goyal dpaa_qp->rx_pkts += num_rx; 2098c3e85bdcSAkhil Goyal dpaa_qp->rx_errs += nb_ops - num_rx; 2099c3e85bdcSAkhil Goyal 2100*f665790aSDavid Marchand DPAA_SEC_DP_DEBUG("SEC Received %d Packets", num_rx); 2101c3e85bdcSAkhil Goyal 2102c3e85bdcSAkhil Goyal return num_rx; 2103c3e85bdcSAkhil Goyal } 2104c3e85bdcSAkhil Goyal 2105c3e85bdcSAkhil Goyal /** Release queue pair */ 2106c3e85bdcSAkhil Goyal static int 2107c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_release(struct rte_cryptodev *dev, 2108c3e85bdcSAkhil Goyal uint16_t qp_id) 2109c3e85bdcSAkhil Goyal { 2110c3e85bdcSAkhil Goyal struct dpaa_sec_dev_private *internals; 2111c3e85bdcSAkhil Goyal struct dpaa_sec_qp *qp = NULL; 2112c3e85bdcSAkhil Goyal 2113c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 2114c3e85bdcSAkhil Goyal 2115f163231eSHemant Agrawal DPAA_SEC_DEBUG("dev =%p, queue =%d", dev, qp_id); 2116c3e85bdcSAkhil Goyal 2117c3e85bdcSAkhil Goyal internals = dev->data->dev_private; 2118c3e85bdcSAkhil Goyal if (qp_id >= internals->max_nb_queue_pairs) { 2119f163231eSHemant Agrawal DPAA_SEC_ERR("Max supported qpid %d", 2120c3e85bdcSAkhil Goyal internals->max_nb_queue_pairs); 2121c3e85bdcSAkhil Goyal return -EINVAL; 2122c3e85bdcSAkhil Goyal } 2123c3e85bdcSAkhil Goyal 2124c3e85bdcSAkhil Goyal qp = &internals->qps[qp_id]; 21252ffb940eSAkhil Goyal rte_mempool_free(qp->ctx_pool); 2126c3e85bdcSAkhil Goyal qp->internals = NULL; 2127c3e85bdcSAkhil Goyal dev->data->queue_pairs[qp_id] = NULL; 2128c3e85bdcSAkhil Goyal 2129c3e85bdcSAkhil Goyal return 0; 2130c3e85bdcSAkhil Goyal } 2131c3e85bdcSAkhil Goyal 2132c3e85bdcSAkhil Goyal /** Setup a queue pair */ 2133c3e85bdcSAkhil Goyal static int 2134c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id, 2135c3e85bdcSAkhil Goyal __rte_unused const struct rte_cryptodev_qp_conf *qp_conf, 2136725d2a7fSFan Zhang __rte_unused int socket_id) 2137c3e85bdcSAkhil Goyal { 2138c3e85bdcSAkhil Goyal struct dpaa_sec_dev_private *internals; 2139c3e85bdcSAkhil Goyal struct dpaa_sec_qp *qp = NULL; 21402ffb940eSAkhil Goyal char str[20]; 2141c3e85bdcSAkhil Goyal 2142f163231eSHemant Agrawal DPAA_SEC_DEBUG("dev =%p, queue =%d, conf =%p", dev, qp_id, qp_conf); 2143c3e85bdcSAkhil Goyal 2144c3e85bdcSAkhil Goyal internals = dev->data->dev_private; 2145c3e85bdcSAkhil Goyal if (qp_id >= internals->max_nb_queue_pairs) { 2146f163231eSHemant Agrawal DPAA_SEC_ERR("Max supported qpid %d", 2147c3e85bdcSAkhil Goyal internals->max_nb_queue_pairs); 2148c3e85bdcSAkhil Goyal return -EINVAL; 2149c3e85bdcSAkhil Goyal } 2150c3e85bdcSAkhil Goyal 2151c3e85bdcSAkhil Goyal qp = &internals->qps[qp_id]; 2152c3e85bdcSAkhil Goyal qp->internals = internals; 21532ffb940eSAkhil Goyal snprintf(str, sizeof(str), "ctx_pool_d%d_qp%d", 21542ffb940eSAkhil Goyal dev->data->dev_id, qp_id); 21552ffb940eSAkhil Goyal if (!qp->ctx_pool) { 21562ffb940eSAkhil Goyal qp->ctx_pool = rte_mempool_create((const char *)str, 21572ffb940eSAkhil Goyal CTX_POOL_NUM_BUFS, 21582ffb940eSAkhil Goyal CTX_POOL_BUF_SIZE, 21592ffb940eSAkhil Goyal CTX_POOL_CACHE_SIZE, 0, 21602ffb940eSAkhil Goyal NULL, NULL, NULL, NULL, 21612ffb940eSAkhil Goyal SOCKET_ID_ANY, 0); 21622ffb940eSAkhil Goyal if (!qp->ctx_pool) { 2163*f665790aSDavid Marchand DPAA_SEC_ERR("%s create failed", str); 21642ffb940eSAkhil Goyal return -ENOMEM; 21652ffb940eSAkhil Goyal } 21662ffb940eSAkhil Goyal } else 21672ffb940eSAkhil Goyal DPAA_SEC_INFO("mempool already created for dev_id : %d, qp: %d", 21682ffb940eSAkhil Goyal dev->data->dev_id, qp_id); 2169c3e85bdcSAkhil Goyal dev->data->queue_pairs[qp_id] = qp; 2170c3e85bdcSAkhil Goyal 2171c3e85bdcSAkhil Goyal return 0; 2172c3e85bdcSAkhil Goyal } 2173c3e85bdcSAkhil Goyal 2174c3e85bdcSAkhil Goyal /** Returns the size of session structure */ 2175c3e85bdcSAkhil Goyal static unsigned int 2176012c5076SPablo de Lara dpaa_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused) 2177c3e85bdcSAkhil Goyal { 2178c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 2179c3e85bdcSAkhil Goyal 2180c3e85bdcSAkhil Goyal return sizeof(dpaa_sec_session); 2181c3e85bdcSAkhil Goyal } 2182c3e85bdcSAkhil Goyal 2183c3e85bdcSAkhil Goyal static int 2184c3e85bdcSAkhil Goyal dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused, 2185c3e85bdcSAkhil Goyal struct rte_crypto_sym_xform *xform, 2186c3e85bdcSAkhil Goyal dpaa_sec_session *session) 2187c3e85bdcSAkhil Goyal { 2188f73d6928SHemant Agrawal session->ctxt = DPAA_SEC_CIPHER; 2189c3e85bdcSAkhil Goyal session->cipher_alg = xform->cipher.algo; 2190c3e85bdcSAkhil Goyal session->iv.length = xform->cipher.iv.length; 2191c3e85bdcSAkhil Goyal session->iv.offset = xform->cipher.iv.offset; 2192c3e85bdcSAkhil Goyal session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length, 2193c3e85bdcSAkhil Goyal RTE_CACHE_LINE_SIZE); 2194c3e85bdcSAkhil Goyal if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) { 2195f163231eSHemant Agrawal DPAA_SEC_ERR("No Memory for cipher key"); 2196c3e85bdcSAkhil Goyal return -ENOMEM; 2197c3e85bdcSAkhil Goyal } 2198c3e85bdcSAkhil Goyal session->cipher_key.length = xform->cipher.key.length; 2199c3e85bdcSAkhil Goyal 2200c3e85bdcSAkhil Goyal memcpy(session->cipher_key.data, xform->cipher.key.data, 2201c3e85bdcSAkhil Goyal xform->cipher.key.length); 22028524b44eSHemant Agrawal switch (xform->cipher.algo) { 22038524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CBC: 22048524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_AES; 22058524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 22068524b44eSHemant Agrawal break; 22073e4fbc6cSGagandeep Singh case RTE_CRYPTO_CIPHER_DES_CBC: 22083e4fbc6cSGagandeep Singh session->cipher_key.alg = OP_ALG_ALGSEL_DES; 22093e4fbc6cSGagandeep Singh session->cipher_key.algmode = OP_ALG_AAI_CBC; 22103e4fbc6cSGagandeep Singh break; 22118524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_3DES_CBC: 22128524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_3DES; 22138524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 22148524b44eSHemant Agrawal break; 22158524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CTR: 22168524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_AES; 22178524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CTR; 22188524b44eSHemant Agrawal break; 22198524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: 22208524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_SNOW_F8; 22218524b44eSHemant Agrawal break; 22228524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_ZUC_EEA3: 22238524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_ZUCE; 22248524b44eSHemant Agrawal break; 22258524b44eSHemant Agrawal default: 222677a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported Cipher specified %s (%u)", 222777a9b5adSHemant Agrawal rte_cryptodev_get_cipher_algo_string(xform->cipher.algo), 22288524b44eSHemant Agrawal xform->cipher.algo); 2229c08ced9aSAkhil Goyal return -ENOTSUP; 22308524b44eSHemant Agrawal } 2231c3e85bdcSAkhil Goyal session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? 2232c3e85bdcSAkhil Goyal DIR_ENC : DIR_DEC; 2233c3e85bdcSAkhil Goyal 2234c3e85bdcSAkhil Goyal return 0; 2235c3e85bdcSAkhil Goyal } 2236c3e85bdcSAkhil Goyal 2237c3e85bdcSAkhil Goyal static int 2238c3e85bdcSAkhil Goyal dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused, 2239c3e85bdcSAkhil Goyal struct rte_crypto_sym_xform *xform, 2240c3e85bdcSAkhil Goyal dpaa_sec_session *session) 2241c3e85bdcSAkhil Goyal { 2242f73d6928SHemant Agrawal session->ctxt = DPAA_SEC_AUTH; 2243c3e85bdcSAkhil Goyal session->auth_alg = xform->auth.algo; 22444c42352cSGagandeep Singh session->auth_key.length = xform->auth.key.length; 22454c42352cSGagandeep Singh if (xform->auth.key.length) { 22464c42352cSGagandeep Singh session->auth_key.data = 22474c42352cSGagandeep Singh rte_zmalloc(NULL, xform->auth.key.length, 2248c3e85bdcSAkhil Goyal RTE_CACHE_LINE_SIZE); 22494c42352cSGagandeep Singh if (session->auth_key.data == NULL) { 2250f163231eSHemant Agrawal DPAA_SEC_ERR("No Memory for auth key"); 2251c3e85bdcSAkhil Goyal return -ENOMEM; 2252c3e85bdcSAkhil Goyal } 22534c42352cSGagandeep Singh memcpy(session->auth_key.data, xform->auth.key.data, 22544c42352cSGagandeep Singh xform->auth.key.length); 22554c42352cSGagandeep Singh 22564c42352cSGagandeep Singh } 2257c3e85bdcSAkhil Goyal session->digest_length = xform->auth.digest_length; 2258c5788a10SHemant Agrawal if (session->cipher_alg == RTE_CRYPTO_CIPHER_NULL) { 2259c5788a10SHemant Agrawal session->iv.offset = xform->auth.iv.offset; 2260c5788a10SHemant Agrawal session->iv.length = xform->auth.iv.length; 2261c5788a10SHemant Agrawal } 2262c3e85bdcSAkhil Goyal 22638524b44eSHemant Agrawal switch (xform->auth.algo) { 22644c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA1: 22654c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_SHA1; 22664c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 22674c42352cSGagandeep Singh break; 22688524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA1_HMAC: 22698524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA1; 22708524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 22718524b44eSHemant Agrawal break; 22724c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_MD5: 22734c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_MD5; 22744c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 22754c42352cSGagandeep Singh break; 22768524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_MD5_HMAC: 22778524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_MD5; 22788524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 22798524b44eSHemant Agrawal break; 22804c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA224: 22814c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_SHA224; 22824c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 22834c42352cSGagandeep Singh break; 22848524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA224_HMAC: 22858524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA224; 22868524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 22878524b44eSHemant Agrawal break; 22884c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA256: 22894c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_SHA256; 22904c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 22914c42352cSGagandeep Singh break; 22928524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA256_HMAC: 22938524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA256; 22948524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 22958524b44eSHemant Agrawal break; 22964c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA384: 22974c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_SHA384; 22984c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 22994c42352cSGagandeep Singh break; 23008524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA384_HMAC: 23018524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA384; 23028524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 23038524b44eSHemant Agrawal break; 23044c42352cSGagandeep Singh case RTE_CRYPTO_AUTH_SHA512: 23054c42352cSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_SHA512; 23064c42352cSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_HASH; 23074c42352cSGagandeep Singh break; 23088524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA512_HMAC: 23098524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA512; 23108524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 23118524b44eSHemant Agrawal break; 23128524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SNOW3G_UIA2: 23138524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SNOW_F9; 23148524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_F9; 23158524b44eSHemant Agrawal break; 23168524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_ZUC_EIA3: 23178524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_ZUCA; 23188524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_F9; 23198524b44eSHemant Agrawal break; 232066f95673SGagandeep Singh case RTE_CRYPTO_AUTH_AES_XCBC_MAC: 232166f95673SGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_AES; 232266f95673SGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_XCBC_MAC; 232366f95673SGagandeep Singh break; 23242ed12d9bSGagandeep Singh case RTE_CRYPTO_AUTH_AES_CMAC: 23252ed12d9bSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_AES; 23262ed12d9bSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_CMAC; 23272ed12d9bSGagandeep Singh break; 23288524b44eSHemant Agrawal default: 232977a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported Auth specified %s (%u)", 233077a9b5adSHemant Agrawal rte_cryptodev_get_auth_algo_string(xform->auth.algo), 23318524b44eSHemant Agrawal xform->auth.algo); 2332c08ced9aSAkhil Goyal return -ENOTSUP; 23338524b44eSHemant Agrawal } 23348524b44eSHemant Agrawal 2335c3e85bdcSAkhil Goyal session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ? 2336c3e85bdcSAkhil Goyal DIR_ENC : DIR_DEC; 2337c3e85bdcSAkhil Goyal 2338c3e85bdcSAkhil Goyal return 0; 2339c3e85bdcSAkhil Goyal } 2340c3e85bdcSAkhil Goyal 2341c3e85bdcSAkhil Goyal static int 23428524b44eSHemant Agrawal dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused, 23438524b44eSHemant Agrawal struct rte_crypto_sym_xform *xform, 23448524b44eSHemant Agrawal dpaa_sec_session *session) 23458524b44eSHemant Agrawal { 23468524b44eSHemant Agrawal 23478524b44eSHemant Agrawal struct rte_crypto_cipher_xform *cipher_xform; 23488524b44eSHemant Agrawal struct rte_crypto_auth_xform *auth_xform; 23498524b44eSHemant Agrawal 2350f73d6928SHemant Agrawal session->ctxt = DPAA_SEC_CIPHER_HASH; 23518524b44eSHemant Agrawal if (session->auth_cipher_text) { 23528524b44eSHemant Agrawal cipher_xform = &xform->cipher; 23538524b44eSHemant Agrawal auth_xform = &xform->next->auth; 23548524b44eSHemant Agrawal } else { 23558524b44eSHemant Agrawal cipher_xform = &xform->next->cipher; 23568524b44eSHemant Agrawal auth_xform = &xform->auth; 23578524b44eSHemant Agrawal } 23588524b44eSHemant Agrawal 23598524b44eSHemant Agrawal /* Set IV parameters */ 23608524b44eSHemant Agrawal session->iv.offset = cipher_xform->iv.offset; 23618524b44eSHemant Agrawal session->iv.length = cipher_xform->iv.length; 23628524b44eSHemant Agrawal 23638524b44eSHemant Agrawal session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length, 23648524b44eSHemant Agrawal RTE_CACHE_LINE_SIZE); 23658524b44eSHemant Agrawal if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) { 23668524b44eSHemant Agrawal DPAA_SEC_ERR("No Memory for cipher key"); 2367c08ced9aSAkhil Goyal return -ENOMEM; 23688524b44eSHemant Agrawal } 23698524b44eSHemant Agrawal session->cipher_key.length = cipher_xform->key.length; 23708524b44eSHemant Agrawal session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length, 23718524b44eSHemant Agrawal RTE_CACHE_LINE_SIZE); 23728524b44eSHemant Agrawal if (session->auth_key.data == NULL && auth_xform->key.length > 0) { 23738524b44eSHemant Agrawal DPAA_SEC_ERR("No Memory for auth key"); 23748524b44eSHemant Agrawal return -ENOMEM; 23758524b44eSHemant Agrawal } 23768524b44eSHemant Agrawal session->auth_key.length = auth_xform->key.length; 23778524b44eSHemant Agrawal memcpy(session->cipher_key.data, cipher_xform->key.data, 23788524b44eSHemant Agrawal cipher_xform->key.length); 23798524b44eSHemant Agrawal memcpy(session->auth_key.data, auth_xform->key.data, 23808524b44eSHemant Agrawal auth_xform->key.length); 23818524b44eSHemant Agrawal 23828524b44eSHemant Agrawal session->digest_length = auth_xform->digest_length; 23838524b44eSHemant Agrawal session->auth_alg = auth_xform->algo; 23848524b44eSHemant Agrawal 23858524b44eSHemant Agrawal switch (auth_xform->algo) { 23868524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA1_HMAC: 23878524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA1; 23888524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 23898524b44eSHemant Agrawal break; 23908524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_MD5_HMAC: 23918524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_MD5; 23928524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 23938524b44eSHemant Agrawal break; 23948524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA224_HMAC: 23958524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA224; 23968524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 23978524b44eSHemant Agrawal break; 23988524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA256_HMAC: 23998524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA256; 24008524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 24018524b44eSHemant Agrawal break; 24028524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA384_HMAC: 24038524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA384; 24048524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 24058524b44eSHemant Agrawal break; 24068524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA512_HMAC: 24078524b44eSHemant Agrawal session->auth_key.alg = OP_ALG_ALGSEL_SHA512; 24088524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 24098524b44eSHemant Agrawal break; 241066f95673SGagandeep Singh case RTE_CRYPTO_AUTH_AES_XCBC_MAC: 241166f95673SGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_AES; 241266f95673SGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_XCBC_MAC; 241366f95673SGagandeep Singh break; 24142ed12d9bSGagandeep Singh case RTE_CRYPTO_AUTH_AES_CMAC: 24152ed12d9bSGagandeep Singh session->auth_key.alg = OP_ALG_ALGSEL_AES; 24162ed12d9bSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_CMAC; 24172ed12d9bSGagandeep Singh break; 24188524b44eSHemant Agrawal default: 241977a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported Auth specified %s (%u)", 242077a9b5adSHemant Agrawal rte_cryptodev_get_auth_algo_string(auth_xform->algo), 24218524b44eSHemant Agrawal auth_xform->algo); 2422c08ced9aSAkhil Goyal return -ENOTSUP; 24238524b44eSHemant Agrawal } 24248524b44eSHemant Agrawal 24258524b44eSHemant Agrawal session->cipher_alg = cipher_xform->algo; 24268524b44eSHemant Agrawal 24278524b44eSHemant Agrawal switch (cipher_xform->algo) { 24288524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CBC: 24298524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_AES; 24308524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 24318524b44eSHemant Agrawal break; 24323e4fbc6cSGagandeep Singh case RTE_CRYPTO_CIPHER_DES_CBC: 24333e4fbc6cSGagandeep Singh session->cipher_key.alg = OP_ALG_ALGSEL_DES; 24343e4fbc6cSGagandeep Singh session->cipher_key.algmode = OP_ALG_AAI_CBC; 24353e4fbc6cSGagandeep Singh break; 24368524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_3DES_CBC: 24378524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_3DES; 24388524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 24398524b44eSHemant Agrawal break; 24408524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CTR: 24418524b44eSHemant Agrawal session->cipher_key.alg = OP_ALG_ALGSEL_AES; 24428524b44eSHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CTR; 24438524b44eSHemant Agrawal break; 24448524b44eSHemant Agrawal default: 244577a9b5adSHemant Agrawal 244677a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Undefined Cipher specified %s (%u)", 244777a9b5adSHemant Agrawal rte_cryptodev_get_cipher_algo_string(cipher_xform->algo), 24488524b44eSHemant Agrawal cipher_xform->algo); 2449c08ced9aSAkhil Goyal return -ENOTSUP; 24508524b44eSHemant Agrawal } 24518524b44eSHemant Agrawal session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? 24528524b44eSHemant Agrawal DIR_ENC : DIR_DEC; 24538524b44eSHemant Agrawal return 0; 24548524b44eSHemant Agrawal } 24558524b44eSHemant Agrawal 24568524b44eSHemant Agrawal static int 2457c3e85bdcSAkhil Goyal dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused, 2458c3e85bdcSAkhil Goyal struct rte_crypto_sym_xform *xform, 2459c3e85bdcSAkhil Goyal dpaa_sec_session *session) 2460c3e85bdcSAkhil Goyal { 2461c3e85bdcSAkhil Goyal session->aead_alg = xform->aead.algo; 24628524b44eSHemant Agrawal session->ctxt = DPAA_SEC_AEAD; 2463c3e85bdcSAkhil Goyal session->iv.length = xform->aead.iv.length; 2464c3e85bdcSAkhil Goyal session->iv.offset = xform->aead.iv.offset; 2465c3e85bdcSAkhil Goyal session->auth_only_len = xform->aead.aad_length; 2466c3e85bdcSAkhil Goyal session->aead_key.data = rte_zmalloc(NULL, xform->aead.key.length, 2467c3e85bdcSAkhil Goyal RTE_CACHE_LINE_SIZE); 2468c3e85bdcSAkhil Goyal if (session->aead_key.data == NULL && xform->aead.key.length > 0) { 2469*f665790aSDavid Marchand DPAA_SEC_ERR("No Memory for aead key"); 2470c3e85bdcSAkhil Goyal return -ENOMEM; 2471c3e85bdcSAkhil Goyal } 2472c3e85bdcSAkhil Goyal session->aead_key.length = xform->aead.key.length; 2473c3e85bdcSAkhil Goyal session->digest_length = xform->aead.digest_length; 2474c3e85bdcSAkhil Goyal 2475c3e85bdcSAkhil Goyal memcpy(session->aead_key.data, xform->aead.key.data, 2476c3e85bdcSAkhil Goyal xform->aead.key.length); 24778524b44eSHemant Agrawal 24788524b44eSHemant Agrawal switch (session->aead_alg) { 24798524b44eSHemant Agrawal case RTE_CRYPTO_AEAD_AES_GCM: 24808524b44eSHemant Agrawal session->aead_key.alg = OP_ALG_ALGSEL_AES; 24818524b44eSHemant Agrawal session->aead_key.algmode = OP_ALG_AAI_GCM; 24828524b44eSHemant Agrawal break; 24838524b44eSHemant Agrawal default: 24848524b44eSHemant Agrawal DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg); 2485c08ced9aSAkhil Goyal return -ENOTSUP; 24868524b44eSHemant Agrawal } 24878524b44eSHemant Agrawal 2488c3e85bdcSAkhil Goyal session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ? 2489c3e85bdcSAkhil Goyal DIR_ENC : DIR_DEC; 2490c3e85bdcSAkhil Goyal 2491c3e85bdcSAkhil Goyal return 0; 2492c3e85bdcSAkhil Goyal } 2493c3e85bdcSAkhil Goyal 2494e79416d1SHemant Agrawal static struct qman_fq * 2495e79416d1SHemant Agrawal dpaa_sec_attach_rxq(struct dpaa_sec_dev_private *qi) 2496c3e85bdcSAkhil Goyal { 2497e79416d1SHemant Agrawal unsigned int i; 2498c3e85bdcSAkhil Goyal 2499fd900d38SGagandeep Singh for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) { 2500e79416d1SHemant Agrawal if (qi->inq_attach[i] == 0) { 2501e79416d1SHemant Agrawal qi->inq_attach[i] = 1; 2502e79416d1SHemant Agrawal return &qi->inq[i]; 2503e79416d1SHemant Agrawal } 2504e79416d1SHemant Agrawal } 2505e621d970SAkhil Goyal DPAA_SEC_WARN("All session in use %u", qi->max_nb_sessions); 2506c3e85bdcSAkhil Goyal 2507e79416d1SHemant Agrawal return NULL; 2508c3e85bdcSAkhil Goyal } 2509c3e85bdcSAkhil Goyal 2510e79416d1SHemant Agrawal static int 2511e79416d1SHemant Agrawal dpaa_sec_detach_rxq(struct dpaa_sec_dev_private *qi, struct qman_fq *fq) 2512e79416d1SHemant Agrawal { 2513e79416d1SHemant Agrawal unsigned int i; 2514c9fd1acdSGagandeep Singh int ret; 2515e79416d1SHemant Agrawal 2516fd900d38SGagandeep Singh for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) { 2517e79416d1SHemant Agrawal if (&qi->inq[i] == fq) { 2518c9fd1acdSGagandeep Singh ret = qman_retire_fq(fq, NULL); 2519c9fd1acdSGagandeep Singh if (ret != 0) 2520*f665790aSDavid Marchand DPAA_SEC_ERR("Queue %d is not retired err: %d", 2521*f665790aSDavid Marchand fq->fqid, ret); 2522b4053c4bSAlok Makhariya qman_oos_fq(fq); 2523e79416d1SHemant Agrawal qi->inq_attach[i] = 0; 2524e79416d1SHemant Agrawal return 0; 2525e79416d1SHemant Agrawal } 2526e79416d1SHemant Agrawal } 2527e79416d1SHemant Agrawal return -1; 2528e79416d1SHemant Agrawal } 2529e79416d1SHemant Agrawal 25309d5f73c2SGagandeep Singh int 2531e79416d1SHemant Agrawal dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess) 2532e79416d1SHemant Agrawal { 2533e79416d1SHemant Agrawal int ret; 2534e79416d1SHemant Agrawal 25354e694fe5SAkhil Goyal sess->qp[rte_lcore_id() % MAX_DPAA_CORES] = qp; 2536e5872221SRohit Raj if (unlikely(!DPAA_PER_LCORE_PORTAL)) { 25375b0f1bd3SAshish Jain ret = rte_dpaa_portal_init((void *)0); 25385b0f1bd3SAshish Jain if (ret) { 2539f163231eSHemant Agrawal DPAA_SEC_ERR("Failure in affining portal"); 25405b0f1bd3SAshish Jain return ret; 25415b0f1bd3SAshish Jain } 25425b0f1bd3SAshish Jain } 25434e694fe5SAkhil Goyal ret = dpaa_sec_init_rx(sess->inq[rte_lcore_id() % MAX_DPAA_CORES], 2544ec861560SGagandeep Singh rte_dpaa_mem_vtop(&sess->cdb), 2545e79416d1SHemant Agrawal qman_fq_fqid(&qp->outq)); 2546e79416d1SHemant Agrawal if (ret) 2547f163231eSHemant Agrawal DPAA_SEC_ERR("Unable to init sec queue"); 2548e79416d1SHemant Agrawal 2549e79416d1SHemant Agrawal return ret; 2550c3e85bdcSAkhil Goyal } 2551c3e85bdcSAkhil Goyal 25526290de2cSLukasz Wojciechowski static inline void 25536290de2cSLukasz Wojciechowski free_session_data(dpaa_sec_session *s) 25546290de2cSLukasz Wojciechowski { 25556290de2cSLukasz Wojciechowski if (is_aead(s)) 25566290de2cSLukasz Wojciechowski rte_free(s->aead_key.data); 25576290de2cSLukasz Wojciechowski else { 25586290de2cSLukasz Wojciechowski rte_free(s->auth_key.data); 25596290de2cSLukasz Wojciechowski rte_free(s->cipher_key.data); 25606290de2cSLukasz Wojciechowski } 25616290de2cSLukasz Wojciechowski memset(s, 0, sizeof(dpaa_sec_session)); 25626290de2cSLukasz Wojciechowski } 25636290de2cSLukasz Wojciechowski 2564c3e85bdcSAkhil Goyal static int 2565c3e85bdcSAkhil Goyal dpaa_sec_set_session_parameters(struct rte_cryptodev *dev, 2566c3e85bdcSAkhil Goyal struct rte_crypto_sym_xform *xform, void *sess) 2567c3e85bdcSAkhil Goyal { 2568c3e85bdcSAkhil Goyal struct dpaa_sec_dev_private *internals = dev->data->dev_private; 2569c3e85bdcSAkhil Goyal dpaa_sec_session *session = sess; 25704e694fe5SAkhil Goyal uint32_t i; 2571f73d6928SHemant Agrawal int ret; 2572c3e85bdcSAkhil Goyal 2573c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 2574c3e85bdcSAkhil Goyal 2575c3e85bdcSAkhil Goyal if (unlikely(sess == NULL)) { 2576f163231eSHemant Agrawal DPAA_SEC_ERR("invalid session struct"); 2577c3e85bdcSAkhil Goyal return -EINVAL; 2578c3e85bdcSAkhil Goyal } 2579b0894102SAkhil Goyal memset(session, 0, sizeof(dpaa_sec_session)); 2580c3e85bdcSAkhil Goyal 2581c3e85bdcSAkhil Goyal /* Default IV length = 0 */ 2582c3e85bdcSAkhil Goyal session->iv.length = 0; 2583c3e85bdcSAkhil Goyal 2584c3e85bdcSAkhil Goyal /* Cipher Only */ 2585c3e85bdcSAkhil Goyal if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) { 2586c3e85bdcSAkhil Goyal session->auth_alg = RTE_CRYPTO_AUTH_NULL; 2587f73d6928SHemant Agrawal ret = dpaa_sec_cipher_init(dev, xform, session); 2588c3e85bdcSAkhil Goyal 2589c3e85bdcSAkhil Goyal /* Authentication Only */ 2590c3e85bdcSAkhil Goyal } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && 2591c3e85bdcSAkhil Goyal xform->next == NULL) { 2592c3e85bdcSAkhil Goyal session->cipher_alg = RTE_CRYPTO_CIPHER_NULL; 25938524b44eSHemant Agrawal session->ctxt = DPAA_SEC_AUTH; 2594f73d6928SHemant Agrawal ret = dpaa_sec_auth_init(dev, xform, session); 2595c3e85bdcSAkhil Goyal 2596c3e85bdcSAkhil Goyal /* Cipher then Authenticate */ 2597c3e85bdcSAkhil Goyal } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && 2598c3e85bdcSAkhil Goyal xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) { 2599c3e85bdcSAkhil Goyal if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 26008524b44eSHemant Agrawal session->auth_cipher_text = 1; 2601f73d6928SHemant Agrawal if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL) 2602f73d6928SHemant Agrawal ret = dpaa_sec_auth_init(dev, xform, session); 2603f73d6928SHemant Agrawal else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL) 2604f73d6928SHemant Agrawal ret = dpaa_sec_cipher_init(dev, xform, session); 2605f73d6928SHemant Agrawal else 2606f73d6928SHemant Agrawal ret = dpaa_sec_chain_init(dev, xform, session); 2607c3e85bdcSAkhil Goyal } else { 2608f163231eSHemant Agrawal DPAA_SEC_ERR("Not supported: Auth then Cipher"); 2609c08ced9aSAkhil Goyal return -ENOTSUP; 2610c3e85bdcSAkhil Goyal } 2611c3e85bdcSAkhil Goyal /* Authenticate then Cipher */ 2612c3e85bdcSAkhil Goyal } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && 2613c3e85bdcSAkhil Goyal xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { 2614c3e85bdcSAkhil Goyal if (xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 26158524b44eSHemant Agrawal session->auth_cipher_text = 0; 2616f73d6928SHemant Agrawal if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL) 2617f73d6928SHemant Agrawal ret = dpaa_sec_cipher_init(dev, xform, session); 2618f73d6928SHemant Agrawal else if (xform->next->cipher.algo 2619f73d6928SHemant Agrawal == RTE_CRYPTO_CIPHER_NULL) 2620f73d6928SHemant Agrawal ret = dpaa_sec_auth_init(dev, xform, session); 2621f73d6928SHemant Agrawal else 2622f73d6928SHemant Agrawal ret = dpaa_sec_chain_init(dev, xform, session); 2623c3e85bdcSAkhil Goyal } else { 2624f163231eSHemant Agrawal DPAA_SEC_ERR("Not supported: Auth then Cipher"); 2625c08ced9aSAkhil Goyal return -ENOTSUP; 2626c3e85bdcSAkhil Goyal } 2627c3e85bdcSAkhil Goyal 2628c3e85bdcSAkhil Goyal /* AEAD operation for AES-GCM kind of Algorithms */ 2629c3e85bdcSAkhil Goyal } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD && 2630c3e85bdcSAkhil Goyal xform->next == NULL) { 2631f73d6928SHemant Agrawal ret = dpaa_sec_aead_init(dev, xform, session); 2632c3e85bdcSAkhil Goyal 2633c3e85bdcSAkhil Goyal } else { 2634f163231eSHemant Agrawal DPAA_SEC_ERR("Invalid crypto type"); 2635c3e85bdcSAkhil Goyal return -EINVAL; 2636c3e85bdcSAkhil Goyal } 2637f73d6928SHemant Agrawal if (ret) { 2638f73d6928SHemant Agrawal DPAA_SEC_ERR("unable to init session"); 2639f73d6928SHemant Agrawal goto err1; 2640f73d6928SHemant Agrawal } 2641f73d6928SHemant Agrawal 26423b617ee7SAkhil Goyal rte_spinlock_lock(&internals->lock); 26434e694fe5SAkhil Goyal for (i = 0; i < MAX_DPAA_CORES; i++) { 26444e694fe5SAkhil Goyal session->inq[i] = dpaa_sec_attach_rxq(internals); 26454e694fe5SAkhil Goyal if (session->inq[i] == NULL) { 2646f163231eSHemant Agrawal DPAA_SEC_ERR("unable to attach sec queue"); 26474e694fe5SAkhil Goyal rte_spinlock_unlock(&internals->lock); 2648c08ced9aSAkhil Goyal ret = -EBUSY; 2649e79416d1SHemant Agrawal goto err1; 2650e79416d1SHemant Agrawal } 26514e694fe5SAkhil Goyal } 26524e694fe5SAkhil Goyal rte_spinlock_unlock(&internals->lock); 2653c3e85bdcSAkhil Goyal 2654c3e85bdcSAkhil Goyal return 0; 2655e79416d1SHemant Agrawal 2656e79416d1SHemant Agrawal err1: 26576290de2cSLukasz Wojciechowski free_session_data(session); 2658c08ced9aSAkhil Goyal return ret; 2659c3e85bdcSAkhil Goyal } 2660c3e85bdcSAkhil Goyal 2661c3e85bdcSAkhil Goyal static int 2662012c5076SPablo de Lara dpaa_sec_sym_session_configure(struct rte_cryptodev *dev, 2663c3e85bdcSAkhil Goyal struct rte_crypto_sym_xform *xform, 2664bdce2564SAkhil Goyal struct rte_cryptodev_sym_session *sess) 2665c3e85bdcSAkhil Goyal { 26662a440d6aSAkhil Goyal void *sess_private_data = CRYPTODEV_GET_SYM_SESS_PRIV(sess); 2667c3e85bdcSAkhil Goyal int ret; 2668c3e85bdcSAkhil Goyal 2669c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 2670c3e85bdcSAkhil Goyal 2671c3e85bdcSAkhil Goyal ret = dpaa_sec_set_session_parameters(dev, xform, sess_private_data); 2672c3e85bdcSAkhil Goyal if (ret != 0) { 2673f163231eSHemant Agrawal DPAA_SEC_ERR("failed to configure session parameters"); 2674c3e85bdcSAkhil Goyal return ret; 2675c3e85bdcSAkhil Goyal } 2676c3e85bdcSAkhil Goyal 267776da1b51SGagandeep Singh ret = dpaa_sec_prep_cdb(sess_private_data); 267876da1b51SGagandeep Singh if (ret) { 267976da1b51SGagandeep Singh DPAA_SEC_ERR("Unable to prepare sec cdb"); 268076da1b51SGagandeep Singh return ret; 268176da1b51SGagandeep Singh } 2682e79416d1SHemant Agrawal 2683c3e85bdcSAkhil Goyal return 0; 2684c3e85bdcSAkhil Goyal } 2685c3e85bdcSAkhil Goyal 26863d0d5332SAkhil Goyal static inline void 26873d0d5332SAkhil Goyal free_session_memory(struct rte_cryptodev *dev, dpaa_sec_session *s) 2688c3e85bdcSAkhil Goyal { 2689e79416d1SHemant Agrawal struct dpaa_sec_dev_private *qi = dev->data->dev_private; 26903d0d5332SAkhil Goyal uint8_t i; 2691e79416d1SHemant Agrawal 2692e621d970SAkhil Goyal for (i = 0; i < MAX_DPAA_CORES; i++) { 2693e621d970SAkhil Goyal if (s->inq[i]) 2694e621d970SAkhil Goyal dpaa_sec_detach_rxq(qi, s->inq[i]); 2695e621d970SAkhil Goyal s->inq[i] = NULL; 2696e621d970SAkhil Goyal s->qp[i] = NULL; 2697e621d970SAkhil Goyal } 26986290de2cSLukasz Wojciechowski free_session_data(s); 26993d0d5332SAkhil Goyal } 27003d0d5332SAkhil Goyal 27013d0d5332SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */ 27023d0d5332SAkhil Goyal static void 27033d0d5332SAkhil Goyal dpaa_sec_sym_session_clear(struct rte_cryptodev *dev, 27043d0d5332SAkhil Goyal struct rte_cryptodev_sym_session *sess) 27053d0d5332SAkhil Goyal { 27063d0d5332SAkhil Goyal PMD_INIT_FUNC_TRACE(); 27072a440d6aSAkhil Goyal void *sess_priv = CRYPTODEV_GET_SYM_SESS_PRIV(sess); 27083d0d5332SAkhil Goyal dpaa_sec_session *s = (dpaa_sec_session *)sess_priv; 27093d0d5332SAkhil Goyal 27103d0d5332SAkhil Goyal free_session_memory(dev, s); 2711c3e85bdcSAkhil Goyal } 2712c3e85bdcSAkhil Goyal 2713c3e85bdcSAkhil Goyal static int 27142c318722SHemant Agrawal dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform, 27152c318722SHemant Agrawal struct rte_security_ipsec_xform *ipsec_xform, 27162c318722SHemant Agrawal dpaa_sec_session *session) 27171f14d500SAkhil Goyal { 27181f14d500SAkhil Goyal PMD_INIT_FUNC_TRACE(); 27191f14d500SAkhil Goyal 27202c318722SHemant Agrawal session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length, 27212c318722SHemant Agrawal RTE_CACHE_LINE_SIZE); 27222c318722SHemant Agrawal if (session->aead_key.data == NULL && aead_xform->key.length > 0) { 27232c318722SHemant Agrawal DPAA_SEC_ERR("No Memory for aead key"); 2724c08ced9aSAkhil Goyal return -ENOMEM; 27251f14d500SAkhil Goyal } 27262c318722SHemant Agrawal memcpy(session->aead_key.data, aead_xform->key.data, 27272c318722SHemant Agrawal aead_xform->key.length); 272805b12700SHemant Agrawal 27292c318722SHemant Agrawal session->digest_length = aead_xform->digest_length; 27302c318722SHemant Agrawal session->aead_key.length = aead_xform->key.length; 27312c318722SHemant Agrawal 27322c318722SHemant Agrawal switch (aead_xform->algo) { 27332c318722SHemant Agrawal case RTE_CRYPTO_AEAD_AES_GCM: 27342c318722SHemant Agrawal switch (session->digest_length) { 27352c318722SHemant Agrawal case 8: 27362c318722SHemant Agrawal session->aead_key.alg = OP_PCL_IPSEC_AES_GCM8; 27372c318722SHemant Agrawal break; 27382c318722SHemant Agrawal case 12: 27392c318722SHemant Agrawal session->aead_key.alg = OP_PCL_IPSEC_AES_GCM12; 27402c318722SHemant Agrawal break; 27412c318722SHemant Agrawal case 16: 27422c318722SHemant Agrawal session->aead_key.alg = OP_PCL_IPSEC_AES_GCM16; 27432c318722SHemant Agrawal break; 27442c318722SHemant Agrawal default: 27452c318722SHemant Agrawal DPAA_SEC_ERR("Crypto: Undefined GCM digest %d", 27462c318722SHemant Agrawal session->digest_length); 2747c08ced9aSAkhil Goyal return -EINVAL; 27482c318722SHemant Agrawal } 27492c318722SHemant Agrawal if (session->dir == DIR_ENC) { 27502c318722SHemant Agrawal memcpy(session->encap_pdb.gcm.salt, 27512c318722SHemant Agrawal (uint8_t *)&(ipsec_xform->salt), 4); 27522c318722SHemant Agrawal } else { 27532c318722SHemant Agrawal memcpy(session->decap_pdb.gcm.salt, 27542c318722SHemant Agrawal (uint8_t *)&(ipsec_xform->salt), 4); 27552c318722SHemant Agrawal } 27562c318722SHemant Agrawal session->aead_key.algmode = OP_ALG_AAI_GCM; 27572c318722SHemant Agrawal session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM; 27582c318722SHemant Agrawal break; 27592c318722SHemant Agrawal default: 27602c318722SHemant Agrawal DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u", 27612c318722SHemant Agrawal aead_xform->algo); 2762c08ced9aSAkhil Goyal return -ENOTSUP; 27632c318722SHemant Agrawal } 27642c318722SHemant Agrawal return 0; 27652c318722SHemant Agrawal } 27662c318722SHemant Agrawal 27672c318722SHemant Agrawal static int 27682c318722SHemant Agrawal dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform, 27692c318722SHemant Agrawal struct rte_crypto_auth_xform *auth_xform, 27701cdfbb0bSVakul Garg struct rte_security_ipsec_xform *ipsec_xform, 27712c318722SHemant Agrawal dpaa_sec_session *session) 27722c318722SHemant Agrawal { 27732c318722SHemant Agrawal if (cipher_xform) { 27741f14d500SAkhil Goyal session->cipher_key.data = rte_zmalloc(NULL, 27751f14d500SAkhil Goyal cipher_xform->key.length, 27761f14d500SAkhil Goyal RTE_CACHE_LINE_SIZE); 27771f14d500SAkhil Goyal if (session->cipher_key.data == NULL && 27781f14d500SAkhil Goyal cipher_xform->key.length > 0) { 2779f163231eSHemant Agrawal DPAA_SEC_ERR("No Memory for cipher key"); 27801f14d500SAkhil Goyal return -ENOMEM; 27811f14d500SAkhil Goyal } 27822c318722SHemant Agrawal 27832c318722SHemant Agrawal session->cipher_key.length = cipher_xform->key.length; 278405b12700SHemant Agrawal memcpy(session->cipher_key.data, cipher_xform->key.data, 278505b12700SHemant Agrawal cipher_xform->key.length); 278605b12700SHemant Agrawal session->cipher_alg = cipher_xform->algo; 278705b12700SHemant Agrawal } else { 278805b12700SHemant Agrawal session->cipher_key.data = NULL; 278905b12700SHemant Agrawal session->cipher_key.length = 0; 279005b12700SHemant Agrawal session->cipher_alg = RTE_CRYPTO_CIPHER_NULL; 279105b12700SHemant Agrawal } 279205b12700SHemant Agrawal 27932c318722SHemant Agrawal if (auth_xform) { 27941f14d500SAkhil Goyal session->auth_key.data = rte_zmalloc(NULL, 27951f14d500SAkhil Goyal auth_xform->key.length, 27961f14d500SAkhil Goyal RTE_CACHE_LINE_SIZE); 27971f14d500SAkhil Goyal if (session->auth_key.data == NULL && 27981f14d500SAkhil Goyal auth_xform->key.length > 0) { 2799f163231eSHemant Agrawal DPAA_SEC_ERR("No Memory for auth key"); 28001f14d500SAkhil Goyal return -ENOMEM; 28011f14d500SAkhil Goyal } 28022c318722SHemant Agrawal session->auth_key.length = auth_xform->key.length; 28031f14d500SAkhil Goyal memcpy(session->auth_key.data, auth_xform->key.data, 28041f14d500SAkhil Goyal auth_xform->key.length); 28052c318722SHemant Agrawal session->auth_alg = auth_xform->algo; 2806247b6908SHemant Agrawal session->digest_length = auth_xform->digest_length; 28072c318722SHemant Agrawal } else { 28082c318722SHemant Agrawal session->auth_key.data = NULL; 28092c318722SHemant Agrawal session->auth_key.length = 0; 28102c318722SHemant Agrawal session->auth_alg = RTE_CRYPTO_AUTH_NULL; 28112c318722SHemant Agrawal } 28121f14d500SAkhil Goyal 28132c318722SHemant Agrawal switch (session->auth_alg) { 28148524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SHA1_HMAC: 28158524b44eSHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA1_96; 28168524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 28178524b44eSHemant Agrawal break; 28182c318722SHemant Agrawal case RTE_CRYPTO_AUTH_MD5_HMAC: 28192c318722SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_MD5_96; 28208524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 28218524b44eSHemant Agrawal break; 28221f14d500SAkhil Goyal case RTE_CRYPTO_AUTH_SHA256_HMAC: 28238524b44eSHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_256_128; 28248524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 2825247b6908SHemant Agrawal if (session->digest_length != 16) 2826247b6908SHemant Agrawal DPAA_SEC_WARN( 2827247b6908SHemant Agrawal "+++Using sha256-hmac truncated len is non-standard," 2828247b6908SHemant Agrawal "it will not work with lookaside proto"); 28298524b44eSHemant Agrawal break; 2830c51ccb96SHemant Agrawal case RTE_CRYPTO_AUTH_SHA224_HMAC: 2831c51ccb96SHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 2832c51ccb96SHemant Agrawal if (session->digest_length == 6) 2833c51ccb96SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_224_96; 2834c51ccb96SHemant Agrawal else if (session->digest_length == 14) 2835c51ccb96SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_224_224; 2836c51ccb96SHemant Agrawal else 2837c51ccb96SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_224_112; 2838c51ccb96SHemant Agrawal break; 28391f14d500SAkhil Goyal case RTE_CRYPTO_AUTH_SHA384_HMAC: 28408524b44eSHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_384_192; 28418524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 28428524b44eSHemant Agrawal break; 28431f14d500SAkhil Goyal case RTE_CRYPTO_AUTH_SHA512_HMAC: 28448524b44eSHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_512_256; 28458524b44eSHemant Agrawal session->auth_key.algmode = OP_ALG_AAI_HMAC; 28461f14d500SAkhil Goyal break; 28472c318722SHemant Agrawal case RTE_CRYPTO_AUTH_AES_CMAC: 28482c318722SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_AES_CMAC_96; 28492ed12d9bSGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_CMAC; 28502c318722SHemant Agrawal break; 28512c318722SHemant Agrawal case RTE_CRYPTO_AUTH_NULL: 28522c318722SHemant Agrawal session->auth_key.alg = OP_PCL_IPSEC_HMAC_NULL; 28532c318722SHemant Agrawal break; 28542c318722SHemant Agrawal case RTE_CRYPTO_AUTH_AES_XCBC_MAC: 285566f95673SGagandeep Singh session->auth_key.alg = OP_PCL_IPSEC_AES_XCBC_MAC_96; 285666f95673SGagandeep Singh session->auth_key.algmode = OP_ALG_AAI_XCBC_MAC; 285766f95673SGagandeep Singh break; 28582c318722SHemant Agrawal default: 285977a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported auth alg %s (%u)", 286077a9b5adSHemant Agrawal rte_cryptodev_get_auth_algo_string(session->auth_alg), 28612c318722SHemant Agrawal session->auth_alg); 2862c08ced9aSAkhil Goyal return -ENOTSUP; 28632c318722SHemant Agrawal } 28642c318722SHemant Agrawal 28652c318722SHemant Agrawal switch (session->cipher_alg) { 28662c318722SHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CBC: 28672c318722SHemant Agrawal session->cipher_key.alg = OP_PCL_IPSEC_AES_CBC; 28682c318722SHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 28692c318722SHemant Agrawal break; 28703e4fbc6cSGagandeep Singh case RTE_CRYPTO_CIPHER_DES_CBC: 28713e4fbc6cSGagandeep Singh session->cipher_key.alg = OP_PCL_IPSEC_DES; 28723e4fbc6cSGagandeep Singh session->cipher_key.algmode = OP_ALG_AAI_CBC; 28733e4fbc6cSGagandeep Singh break; 28742c318722SHemant Agrawal case RTE_CRYPTO_CIPHER_3DES_CBC: 28752c318722SHemant Agrawal session->cipher_key.alg = OP_PCL_IPSEC_3DES; 28762c318722SHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CBC; 28772c318722SHemant Agrawal break; 28782c318722SHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CTR: 28792c318722SHemant Agrawal session->cipher_key.alg = OP_PCL_IPSEC_AES_CTR; 28802c318722SHemant Agrawal session->cipher_key.algmode = OP_ALG_AAI_CTR; 28811cdfbb0bSVakul Garg if (session->dir == DIR_ENC) { 28821cdfbb0bSVakul Garg session->encap_pdb.ctr.ctr_initial = 0x00000001; 28831cdfbb0bSVakul Garg session->encap_pdb.ctr.ctr_nonce = ipsec_xform->salt; 28841cdfbb0bSVakul Garg } else { 28851cdfbb0bSVakul Garg session->decap_pdb.ctr.ctr_initial = 0x00000001; 28861cdfbb0bSVakul Garg session->decap_pdb.ctr.ctr_nonce = ipsec_xform->salt; 28871cdfbb0bSVakul Garg } 28882c318722SHemant Agrawal break; 28892c318722SHemant Agrawal case RTE_CRYPTO_CIPHER_NULL: 28902c318722SHemant Agrawal session->cipher_key.alg = OP_PCL_IPSEC_NULL; 28912c318722SHemant Agrawal break; 28922c318722SHemant Agrawal default: 289377a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %s (%u)", 289477a9b5adSHemant Agrawal rte_cryptodev_get_cipher_algo_string(session->cipher_alg), 28952c318722SHemant Agrawal session->cipher_alg); 2896c08ced9aSAkhil Goyal return -ENOTSUP; 28972c318722SHemant Agrawal } 28982c318722SHemant Agrawal 28992c318722SHemant Agrawal return 0; 29002c318722SHemant Agrawal } 29012c318722SHemant Agrawal 29022c318722SHemant Agrawal static int 29032c318722SHemant Agrawal dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev, 29042c318722SHemant Agrawal struct rte_security_session_conf *conf, 29052c318722SHemant Agrawal void *sess) 29062c318722SHemant Agrawal { 29072c318722SHemant Agrawal struct dpaa_sec_dev_private *internals = dev->data->dev_private; 29082c318722SHemant Agrawal struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec; 29092c318722SHemant Agrawal struct rte_crypto_auth_xform *auth_xform = NULL; 29102c318722SHemant Agrawal struct rte_crypto_cipher_xform *cipher_xform = NULL; 29112c318722SHemant Agrawal struct rte_crypto_aead_xform *aead_xform = NULL; 29122c318722SHemant Agrawal dpaa_sec_session *session = (dpaa_sec_session *)sess; 29132c318722SHemant Agrawal uint32_t i; 29142c318722SHemant Agrawal int ret; 29152c318722SHemant Agrawal 29162c318722SHemant Agrawal PMD_INIT_FUNC_TRACE(); 29172c318722SHemant Agrawal 29182c318722SHemant Agrawal memset(session, 0, sizeof(dpaa_sec_session)); 29192c318722SHemant Agrawal session->proto_alg = conf->protocol; 29202c318722SHemant Agrawal session->ctxt = DPAA_SEC_IPSEC; 29212c318722SHemant Agrawal 29228f4125c1SGagandeep Singh if (ipsec_xform->life.bytes_hard_limit != 0 || 29238f4125c1SGagandeep Singh ipsec_xform->life.bytes_soft_limit != 0 || 29248f4125c1SGagandeep Singh ipsec_xform->life.packets_hard_limit != 0 || 29258f4125c1SGagandeep Singh ipsec_xform->life.packets_soft_limit != 0) 29268f4125c1SGagandeep Singh return -ENOTSUP; 29278f4125c1SGagandeep Singh 29282c318722SHemant Agrawal if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 29292c318722SHemant Agrawal session->dir = DIR_ENC; 29302c318722SHemant Agrawal else 29312c318722SHemant Agrawal session->dir = DIR_DEC; 29322c318722SHemant Agrawal 29332c318722SHemant Agrawal if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { 29342c318722SHemant Agrawal cipher_xform = &conf->crypto_xform->cipher; 29352c318722SHemant Agrawal if (conf->crypto_xform->next) 29362c318722SHemant Agrawal auth_xform = &conf->crypto_xform->next->auth; 29372c318722SHemant Agrawal ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform, 29381cdfbb0bSVakul Garg ipsec_xform, session); 29392c318722SHemant Agrawal } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) { 29402c318722SHemant Agrawal auth_xform = &conf->crypto_xform->auth; 29412c318722SHemant Agrawal if (conf->crypto_xform->next) 29422c318722SHemant Agrawal cipher_xform = &conf->crypto_xform->next->cipher; 29432c318722SHemant Agrawal ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform, 29441cdfbb0bSVakul Garg ipsec_xform, session); 29452c318722SHemant Agrawal } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) { 29462c318722SHemant Agrawal aead_xform = &conf->crypto_xform->aead; 29472c318722SHemant Agrawal ret = dpaa_sec_ipsec_aead_init(aead_xform, 29482c318722SHemant Agrawal ipsec_xform, session); 29492c318722SHemant Agrawal } else { 29502c318722SHemant Agrawal DPAA_SEC_ERR("XFORM not specified"); 29512c318722SHemant Agrawal ret = -EINVAL; 29521f14d500SAkhil Goyal goto out; 29531f14d500SAkhil Goyal } 29542c318722SHemant Agrawal if (ret) { 29552c318722SHemant Agrawal DPAA_SEC_ERR("Failed to process xform"); 29562c318722SHemant Agrawal goto out; 29571f14d500SAkhil Goyal } 29581f14d500SAkhil Goyal 29591f14d500SAkhil Goyal if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 29605ab35d2eSAkhil Goyal if (ipsec_xform->tunnel.type == 29615ab35d2eSAkhil Goyal RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 29621f14d500SAkhil Goyal session->ip4_hdr.ip_v = IPVERSION; 29631f14d500SAkhil Goyal session->ip4_hdr.ip_hl = 5; 29641f14d500SAkhil Goyal session->ip4_hdr.ip_len = rte_cpu_to_be_16( 29651f14d500SAkhil Goyal sizeof(session->ip4_hdr)); 29661f14d500SAkhil Goyal session->ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp; 29671f14d500SAkhil Goyal session->ip4_hdr.ip_id = 0; 29681f14d500SAkhil Goyal session->ip4_hdr.ip_off = 0; 29691f14d500SAkhil Goyal session->ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl; 29701f14d500SAkhil Goyal session->ip4_hdr.ip_p = (ipsec_xform->proto == 29715ab35d2eSAkhil Goyal RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? 29725ab35d2eSAkhil Goyal IPPROTO_ESP : IPPROTO_AH; 29731f14d500SAkhil Goyal session->ip4_hdr.ip_sum = 0; 29745ab35d2eSAkhil Goyal session->ip4_hdr.ip_src = 29755ab35d2eSAkhil Goyal ipsec_xform->tunnel.ipv4.src_ip; 29765ab35d2eSAkhil Goyal session->ip4_hdr.ip_dst = 29775ab35d2eSAkhil Goyal ipsec_xform->tunnel.ipv4.dst_ip; 29781f14d500SAkhil Goyal session->ip4_hdr.ip_sum = calc_chksum((uint16_t *) 29791f14d500SAkhil Goyal (void *)&session->ip4_hdr, 29801f14d500SAkhil Goyal sizeof(struct ip)); 29815ab35d2eSAkhil Goyal session->encap_pdb.ip_hdr_len = sizeof(struct ip); 29825ab35d2eSAkhil Goyal } else if (ipsec_xform->tunnel.type == 29835ab35d2eSAkhil Goyal RTE_SECURITY_IPSEC_TUNNEL_IPV6) { 29845ab35d2eSAkhil Goyal session->ip6_hdr.vtc_flow = rte_cpu_to_be_32( 29855ab35d2eSAkhil Goyal DPAA_IPv6_DEFAULT_VTC_FLOW | 29865ab35d2eSAkhil Goyal ((ipsec_xform->tunnel.ipv6.dscp << 29875ab35d2eSAkhil Goyal RTE_IPV6_HDR_TC_SHIFT) & 29885ab35d2eSAkhil Goyal RTE_IPV6_HDR_TC_MASK) | 29895ab35d2eSAkhil Goyal ((ipsec_xform->tunnel.ipv6.flabel << 29905ab35d2eSAkhil Goyal RTE_IPV6_HDR_FL_SHIFT) & 29915ab35d2eSAkhil Goyal RTE_IPV6_HDR_FL_MASK)); 29925ab35d2eSAkhil Goyal /* Payload length will be updated by HW */ 29935ab35d2eSAkhil Goyal session->ip6_hdr.payload_len = 0; 29945ab35d2eSAkhil Goyal session->ip6_hdr.hop_limits = 29955ab35d2eSAkhil Goyal ipsec_xform->tunnel.ipv6.hlimit; 29965ab35d2eSAkhil Goyal session->ip6_hdr.proto = (ipsec_xform->proto == 29975ab35d2eSAkhil Goyal RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? 29985ab35d2eSAkhil Goyal IPPROTO_ESP : IPPROTO_AH; 29995ab35d2eSAkhil Goyal memcpy(&session->ip6_hdr.src_addr, 30005ab35d2eSAkhil Goyal &ipsec_xform->tunnel.ipv6.src_addr, 16); 30015ab35d2eSAkhil Goyal memcpy(&session->ip6_hdr.dst_addr, 30025ab35d2eSAkhil Goyal &ipsec_xform->tunnel.ipv6.dst_addr, 16); 30035ab35d2eSAkhil Goyal session->encap_pdb.ip_hdr_len = 30045ab35d2eSAkhil Goyal sizeof(struct rte_ipv6_hdr); 30055ab35d2eSAkhil Goyal } 30060aa5986cSGagandeep Singh 30071f14d500SAkhil Goyal session->encap_pdb.options = 30081f14d500SAkhil Goyal (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) | 30091f14d500SAkhil Goyal PDBOPTS_ESP_OIHI_PDB_INL | 30101f14d500SAkhil Goyal PDBOPTS_ESP_IVSRC | 301179fde9d0SAkhil Goyal PDBHMO_ESP_SNR; 30120aa5986cSGagandeep Singh if (ipsec_xform->options.dec_ttl) 30130aa5986cSGagandeep Singh session->encap_pdb.options |= PDBHMO_ESP_ENCAP_DTTL; 30140f318781SAkhil Goyal if (ipsec_xform->options.esn) 30150f318781SAkhil Goyal session->encap_pdb.options |= PDBOPTS_ESP_ESN; 30161f14d500SAkhil Goyal session->encap_pdb.spi = ipsec_xform->spi; 30172c318722SHemant Agrawal 30181f14d500SAkhil Goyal } else if (ipsec_xform->direction == 30191f14d500SAkhil Goyal RTE_SECURITY_IPSEC_SA_DIR_INGRESS) { 30205ab35d2eSAkhil Goyal if (ipsec_xform->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4) 30211f14d500SAkhil Goyal session->decap_pdb.options = sizeof(struct ip) << 16; 30225ab35d2eSAkhil Goyal else 30235ab35d2eSAkhil Goyal session->decap_pdb.options = 30245ab35d2eSAkhil Goyal sizeof(struct rte_ipv6_hdr) << 16; 30250f318781SAkhil Goyal if (ipsec_xform->options.esn) 30260f318781SAkhil Goyal session->decap_pdb.options |= PDBOPTS_ESP_ESN; 3027a37ce227SHemant Agrawal if (ipsec_xform->replay_win_sz) { 3028a37ce227SHemant Agrawal uint32_t win_sz; 3029a37ce227SHemant Agrawal win_sz = rte_align32pow2(ipsec_xform->replay_win_sz); 3030a37ce227SHemant Agrawal 3031a37ce227SHemant Agrawal switch (win_sz) { 3032a37ce227SHemant Agrawal case 1: 3033a37ce227SHemant Agrawal case 2: 3034a37ce227SHemant Agrawal case 4: 3035a37ce227SHemant Agrawal case 8: 3036a37ce227SHemant Agrawal case 16: 3037a37ce227SHemant Agrawal case 32: 3038a37ce227SHemant Agrawal session->decap_pdb.options |= PDBOPTS_ESP_ARS32; 3039a37ce227SHemant Agrawal break; 3040a37ce227SHemant Agrawal case 64: 3041a37ce227SHemant Agrawal session->decap_pdb.options |= PDBOPTS_ESP_ARS64; 3042a37ce227SHemant Agrawal break; 3043a37ce227SHemant Agrawal default: 3044a37ce227SHemant Agrawal session->decap_pdb.options |= 3045a37ce227SHemant Agrawal PDBOPTS_ESP_ARS128; 3046a37ce227SHemant Agrawal } 3047a37ce227SHemant Agrawal } 30481f14d500SAkhil Goyal } else 30491f14d500SAkhil Goyal goto out; 30503b617ee7SAkhil Goyal rte_spinlock_lock(&internals->lock); 30514e694fe5SAkhil Goyal for (i = 0; i < MAX_DPAA_CORES; i++) { 30524e694fe5SAkhil Goyal session->inq[i] = dpaa_sec_attach_rxq(internals); 30534e694fe5SAkhil Goyal if (session->inq[i] == NULL) { 3054f163231eSHemant Agrawal DPAA_SEC_ERR("unable to attach sec queue"); 30554e694fe5SAkhil Goyal rte_spinlock_unlock(&internals->lock); 30561f14d500SAkhil Goyal goto out; 30571f14d500SAkhil Goyal } 30584e694fe5SAkhil Goyal } 30594e694fe5SAkhil Goyal rte_spinlock_unlock(&internals->lock); 30601f14d500SAkhil Goyal 3061a1173d55SHemant Agrawal return 0; 3062a1173d55SHemant Agrawal out: 30636290de2cSLukasz Wojciechowski free_session_data(session); 3064a1173d55SHemant Agrawal return -1; 3065a1173d55SHemant Agrawal } 30661f14d500SAkhil Goyal 3067a1173d55SHemant Agrawal static int 3068a1173d55SHemant Agrawal dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev, 3069a1173d55SHemant Agrawal struct rte_security_session_conf *conf, 3070a1173d55SHemant Agrawal void *sess) 3071a1173d55SHemant Agrawal { 3072a1173d55SHemant Agrawal struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp; 3073a1173d55SHemant Agrawal struct rte_crypto_sym_xform *xform = conf->crypto_xform; 3074a1173d55SHemant Agrawal struct rte_crypto_auth_xform *auth_xform = NULL; 3075a1173d55SHemant Agrawal struct rte_crypto_cipher_xform *cipher_xform = NULL; 3076a1173d55SHemant Agrawal dpaa_sec_session *session = (dpaa_sec_session *)sess; 3077a1173d55SHemant Agrawal struct dpaa_sec_dev_private *dev_priv = dev->data->dev_private; 30784e694fe5SAkhil Goyal uint32_t i; 3079c08ced9aSAkhil Goyal int ret; 3080a1173d55SHemant Agrawal 3081a1173d55SHemant Agrawal PMD_INIT_FUNC_TRACE(); 3082a1173d55SHemant Agrawal 3083a1173d55SHemant Agrawal memset(session, 0, sizeof(dpaa_sec_session)); 3084a1173d55SHemant Agrawal 3085a1173d55SHemant Agrawal /* find xfrm types */ 3086a1173d55SHemant Agrawal if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { 3087a1173d55SHemant Agrawal cipher_xform = &xform->cipher; 308899cc26f6SHemant Agrawal if (xform->next != NULL && 308999cc26f6SHemant Agrawal xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) 3090a1173d55SHemant Agrawal auth_xform = &xform->next->auth; 3091a1173d55SHemant Agrawal } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) { 3092a1173d55SHemant Agrawal auth_xform = &xform->auth; 309399cc26f6SHemant Agrawal if (xform->next != NULL && 309499cc26f6SHemant Agrawal xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) 3095a1173d55SHemant Agrawal cipher_xform = &xform->next->cipher; 3096a1173d55SHemant Agrawal } else { 3097a1173d55SHemant Agrawal DPAA_SEC_ERR("Invalid crypto type"); 3098a1173d55SHemant Agrawal return -EINVAL; 3099a1173d55SHemant Agrawal } 3100a1173d55SHemant Agrawal 3101a1173d55SHemant Agrawal session->proto_alg = conf->protocol; 31028524b44eSHemant Agrawal session->ctxt = DPAA_SEC_PDCP; 31038524b44eSHemant Agrawal 3104a1173d55SHemant Agrawal if (cipher_xform) { 31058524b44eSHemant Agrawal switch (cipher_xform->algo) { 31068524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: 31078524b44eSHemant Agrawal session->cipher_key.alg = PDCP_CIPHER_TYPE_SNOW; 31088524b44eSHemant Agrawal break; 31098524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_ZUC_EEA3: 31108524b44eSHemant Agrawal session->cipher_key.alg = PDCP_CIPHER_TYPE_ZUC; 31118524b44eSHemant Agrawal break; 31128524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_AES_CTR: 31138524b44eSHemant Agrawal session->cipher_key.alg = PDCP_CIPHER_TYPE_AES; 31148524b44eSHemant Agrawal break; 31158524b44eSHemant Agrawal case RTE_CRYPTO_CIPHER_NULL: 31168524b44eSHemant Agrawal session->cipher_key.alg = PDCP_CIPHER_TYPE_NULL; 31178524b44eSHemant Agrawal break; 31188524b44eSHemant Agrawal default: 31198524b44eSHemant Agrawal DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u", 31208524b44eSHemant Agrawal session->cipher_alg); 3121c08ced9aSAkhil Goyal return -EINVAL; 31228524b44eSHemant Agrawal } 31238524b44eSHemant Agrawal 3124a1173d55SHemant Agrawal session->cipher_key.data = rte_zmalloc(NULL, 3125a1173d55SHemant Agrawal cipher_xform->key.length, 3126a1173d55SHemant Agrawal RTE_CACHE_LINE_SIZE); 3127a1173d55SHemant Agrawal if (session->cipher_key.data == NULL && 3128a1173d55SHemant Agrawal cipher_xform->key.length > 0) { 3129a1173d55SHemant Agrawal DPAA_SEC_ERR("No Memory for cipher key"); 3130a1173d55SHemant Agrawal return -ENOMEM; 3131a1173d55SHemant Agrawal } 3132a1173d55SHemant Agrawal session->cipher_key.length = cipher_xform->key.length; 3133a1173d55SHemant Agrawal memcpy(session->cipher_key.data, cipher_xform->key.data, 3134a1173d55SHemant Agrawal cipher_xform->key.length); 3135a1173d55SHemant Agrawal session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? 3136a1173d55SHemant Agrawal DIR_ENC : DIR_DEC; 3137a1173d55SHemant Agrawal session->cipher_alg = cipher_xform->algo; 3138a1173d55SHemant Agrawal } else { 3139a1173d55SHemant Agrawal session->cipher_key.data = NULL; 3140a1173d55SHemant Agrawal session->cipher_key.length = 0; 3141a1173d55SHemant Agrawal session->cipher_alg = RTE_CRYPTO_CIPHER_NULL; 3142a1173d55SHemant Agrawal session->dir = DIR_ENC; 3143a1173d55SHemant Agrawal } 3144a1173d55SHemant Agrawal 3145a1173d55SHemant Agrawal if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) { 3146eac60082SVakul Garg if (pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_5 && 3147eac60082SVakul Garg pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_12) { 3148a1173d55SHemant Agrawal DPAA_SEC_ERR( 3149eac60082SVakul Garg "PDCP Seq Num size should be 5/12 bits for cmode"); 3150c08ced9aSAkhil Goyal ret = -EINVAL; 3151a1173d55SHemant Agrawal goto out; 3152a1173d55SHemant Agrawal } 31532e4cbdb4SVakul Garg } 31542e4cbdb4SVakul Garg 3155a1173d55SHemant Agrawal if (auth_xform) { 31568524b44eSHemant Agrawal switch (auth_xform->algo) { 31578524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_SNOW3G_UIA2: 31588524b44eSHemant Agrawal session->auth_key.alg = PDCP_AUTH_TYPE_SNOW; 31598524b44eSHemant Agrawal break; 31608524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_ZUC_EIA3: 31618524b44eSHemant Agrawal session->auth_key.alg = PDCP_AUTH_TYPE_ZUC; 31628524b44eSHemant Agrawal break; 31638524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_AES_CMAC: 31648524b44eSHemant Agrawal session->auth_key.alg = PDCP_AUTH_TYPE_AES; 31658524b44eSHemant Agrawal break; 31668524b44eSHemant Agrawal case RTE_CRYPTO_AUTH_NULL: 31678524b44eSHemant Agrawal session->auth_key.alg = PDCP_AUTH_TYPE_NULL; 31688524b44eSHemant Agrawal break; 31698524b44eSHemant Agrawal default: 317077a9b5adSHemant Agrawal DPAA_SEC_ERR("Crypto: Unsupported auth alg %s (%u)", 317177a9b5adSHemant Agrawal rte_cryptodev_get_auth_algo_string(session->auth_alg), 31728524b44eSHemant Agrawal session->auth_alg); 31738524b44eSHemant Agrawal rte_free(session->cipher_key.data); 3174c08ced9aSAkhil Goyal return -EINVAL; 31758524b44eSHemant Agrawal } 3176a1173d55SHemant Agrawal session->auth_key.data = rte_zmalloc(NULL, 3177a1173d55SHemant Agrawal auth_xform->key.length, 3178a1173d55SHemant Agrawal RTE_CACHE_LINE_SIZE); 31792e4cbdb4SVakul Garg if (!session->auth_key.data && 3180a1173d55SHemant Agrawal auth_xform->key.length > 0) { 3181a1173d55SHemant Agrawal DPAA_SEC_ERR("No Memory for auth key"); 3182a1173d55SHemant Agrawal rte_free(session->cipher_key.data); 3183a1173d55SHemant Agrawal return -ENOMEM; 3184a1173d55SHemant Agrawal } 3185a1173d55SHemant Agrawal session->auth_key.length = auth_xform->key.length; 3186a1173d55SHemant Agrawal memcpy(session->auth_key.data, auth_xform->key.data, 3187a1173d55SHemant Agrawal auth_xform->key.length); 3188a1173d55SHemant Agrawal session->auth_alg = auth_xform->algo; 3189a1173d55SHemant Agrawal } else { 31901182b364SGagandeep Singh if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) { 31911182b364SGagandeep Singh DPAA_SEC_ERR("Crypto: Integrity must for c-plane"); 31921182b364SGagandeep Singh ret = -EINVAL; 31931182b364SGagandeep Singh goto out; 31941182b364SGagandeep Singh } 3195a1173d55SHemant Agrawal session->auth_key.data = NULL; 3196a1173d55SHemant Agrawal session->auth_key.length = 0; 31972e4cbdb4SVakul Garg session->auth_alg = 0; 3198a1173d55SHemant Agrawal } 3199a1173d55SHemant Agrawal session->pdcp.domain = pdcp_xform->domain; 3200a1173d55SHemant Agrawal session->pdcp.bearer = pdcp_xform->bearer; 3201a1173d55SHemant Agrawal session->pdcp.pkt_dir = pdcp_xform->pkt_dir; 3202a1173d55SHemant Agrawal session->pdcp.sn_size = pdcp_xform->sn_size; 3203a1173d55SHemant Agrawal session->pdcp.hfn = pdcp_xform->hfn; 3204a1173d55SHemant Agrawal session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold; 32056a0c9d36SAkhil Goyal session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd; 32065a4954bcSAkhil Goyal session->pdcp.sdap_enabled = pdcp_xform->sdap_enabled; 32078839c8a1SYunjian Wang if (cipher_xform) 32086a0c9d36SAkhil Goyal session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset; 3209a1173d55SHemant Agrawal 3210a1173d55SHemant Agrawal rte_spinlock_lock(&dev_priv->lock); 32114e694fe5SAkhil Goyal for (i = 0; i < MAX_DPAA_CORES; i++) { 32124e694fe5SAkhil Goyal session->inq[i] = dpaa_sec_attach_rxq(dev_priv); 32134e694fe5SAkhil Goyal if (session->inq[i] == NULL) { 3214a1173d55SHemant Agrawal DPAA_SEC_ERR("unable to attach sec queue"); 32154e694fe5SAkhil Goyal rte_spinlock_unlock(&dev_priv->lock); 3216c08ced9aSAkhil Goyal ret = -EBUSY; 3217a1173d55SHemant Agrawal goto out; 3218a1173d55SHemant Agrawal } 32194e694fe5SAkhil Goyal } 32204e694fe5SAkhil Goyal rte_spinlock_unlock(&dev_priv->lock); 32211f14d500SAkhil Goyal return 0; 32221f14d500SAkhil Goyal out: 32231f14d500SAkhil Goyal rte_free(session->auth_key.data); 32241f14d500SAkhil Goyal rte_free(session->cipher_key.data); 32251f14d500SAkhil Goyal memset(session, 0, sizeof(dpaa_sec_session)); 3226c08ced9aSAkhil Goyal return ret; 32271f14d500SAkhil Goyal } 32281f14d500SAkhil Goyal 32291f14d500SAkhil Goyal static int 32301f14d500SAkhil Goyal dpaa_sec_security_session_create(void *dev, 32311f14d500SAkhil Goyal struct rte_security_session_conf *conf, 32323f3fc330SAkhil Goyal struct rte_security_session *sess) 32331f14d500SAkhil Goyal { 32343f3fc330SAkhil Goyal void *sess_private_data = SECURITY_GET_SESS_PRIV(sess); 32351f14d500SAkhil Goyal struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev; 32361f14d500SAkhil Goyal int ret; 32371f14d500SAkhil Goyal 32381f14d500SAkhil Goyal switch (conf->protocol) { 32391f14d500SAkhil Goyal case RTE_SECURITY_PROTOCOL_IPSEC: 32401f14d500SAkhil Goyal ret = dpaa_sec_set_ipsec_session(cdev, conf, 32411f14d500SAkhil Goyal sess_private_data); 32421f14d500SAkhil Goyal break; 3243a1173d55SHemant Agrawal case RTE_SECURITY_PROTOCOL_PDCP: 3244a1173d55SHemant Agrawal ret = dpaa_sec_set_pdcp_session(cdev, conf, 3245a1173d55SHemant Agrawal sess_private_data); 3246a1173d55SHemant Agrawal break; 32471f14d500SAkhil Goyal case RTE_SECURITY_PROTOCOL_MACSEC: 32481f14d500SAkhil Goyal return -ENOTSUP; 32491f14d500SAkhil Goyal default: 32501f14d500SAkhil Goyal return -EINVAL; 32511f14d500SAkhil Goyal } 32521f14d500SAkhil Goyal if (ret != 0) { 3253f163231eSHemant Agrawal DPAA_SEC_ERR("failed to configure session parameters"); 32541f14d500SAkhil Goyal return ret; 32551f14d500SAkhil Goyal } 32561f14d500SAkhil Goyal 325776da1b51SGagandeep Singh ret = dpaa_sec_prep_cdb(sess_private_data); 325876da1b51SGagandeep Singh if (ret) { 325976da1b51SGagandeep Singh DPAA_SEC_ERR("Unable to prepare sec cdb"); 326076da1b51SGagandeep Singh return ret; 326176da1b51SGagandeep Singh } 326276da1b51SGagandeep Singh 32631f14d500SAkhil Goyal return ret; 32641f14d500SAkhil Goyal } 32651f14d500SAkhil Goyal 32661f14d500SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */ 32671f14d500SAkhil Goyal static int 32681f14d500SAkhil Goyal dpaa_sec_security_session_destroy(void *dev __rte_unused, 32691f14d500SAkhil Goyal struct rte_security_session *sess) 32701f14d500SAkhil Goyal { 32711f14d500SAkhil Goyal PMD_INIT_FUNC_TRACE(); 32723f3fc330SAkhil Goyal void *sess_priv = SECURITY_GET_SESS_PRIV(sess); 32731f14d500SAkhil Goyal dpaa_sec_session *s = (dpaa_sec_session *)sess_priv; 32741f14d500SAkhil Goyal 32751f14d500SAkhil Goyal if (sess_priv) { 32763d0d5332SAkhil Goyal free_session_memory((struct rte_cryptodev *)dev, s); 32771f14d500SAkhil Goyal } 32781f14d500SAkhil Goyal return 0; 32791f14d500SAkhil Goyal } 328066837861SAkhil Goyal 328166837861SAkhil Goyal static unsigned int 328266837861SAkhil Goyal dpaa_sec_security_session_get_size(void *device __rte_unused) 328366837861SAkhil Goyal { 328466837861SAkhil Goyal return sizeof(dpaa_sec_session); 328566837861SAkhil Goyal } 328666837861SAkhil Goyal 32871f14d500SAkhil Goyal static int 32882ffb940eSAkhil Goyal dpaa_sec_dev_configure(struct rte_cryptodev *dev __rte_unused, 3289c3e85bdcSAkhil Goyal struct rte_cryptodev_config *config __rte_unused) 3290c3e85bdcSAkhil Goyal { 3291c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 3292c3e85bdcSAkhil Goyal 3293c3e85bdcSAkhil Goyal return 0; 3294c3e85bdcSAkhil Goyal } 3295c3e85bdcSAkhil Goyal 3296c3e85bdcSAkhil Goyal static int 3297c3e85bdcSAkhil Goyal dpaa_sec_dev_start(struct rte_cryptodev *dev __rte_unused) 3298c3e85bdcSAkhil Goyal { 3299c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 3300c3e85bdcSAkhil Goyal return 0; 3301c3e85bdcSAkhil Goyal } 3302c3e85bdcSAkhil Goyal 3303c3e85bdcSAkhil Goyal static void 3304c3e85bdcSAkhil Goyal dpaa_sec_dev_stop(struct rte_cryptodev *dev __rte_unused) 3305c3e85bdcSAkhil Goyal { 3306c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 3307c3e85bdcSAkhil Goyal } 3308c3e85bdcSAkhil Goyal 3309c3e85bdcSAkhil Goyal static int 33107e3e2954SAkhil Goyal dpaa_sec_dev_close(struct rte_cryptodev *dev) 3311c3e85bdcSAkhil Goyal { 3312c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 33137e3e2954SAkhil Goyal 33147e3e2954SAkhil Goyal if (dev == NULL) 33157e3e2954SAkhil Goyal return -ENOMEM; 33167e3e2954SAkhil Goyal 3317c3e85bdcSAkhil Goyal return 0; 3318c3e85bdcSAkhil Goyal } 3319c3e85bdcSAkhil Goyal 3320c3e85bdcSAkhil Goyal static void 3321c3e85bdcSAkhil Goyal dpaa_sec_dev_infos_get(struct rte_cryptodev *dev, 3322c3e85bdcSAkhil Goyal struct rte_cryptodev_info *info) 3323c3e85bdcSAkhil Goyal { 3324c3e85bdcSAkhil Goyal struct dpaa_sec_dev_private *internals = dev->data->dev_private; 3325c3e85bdcSAkhil Goyal 3326c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 3327c3e85bdcSAkhil Goyal if (info != NULL) { 3328c3e85bdcSAkhil Goyal info->max_nb_queue_pairs = internals->max_nb_queue_pairs; 3329c3e85bdcSAkhil Goyal info->feature_flags = dev->feature_flags; 3330c3e85bdcSAkhil Goyal info->capabilities = dpaa_sec_capabilities; 3331c3e85bdcSAkhil Goyal info->sym.max_nb_sessions = internals->max_nb_sessions; 33329d5f73c2SGagandeep Singh info->driver_id = dpaa_cryptodev_driver_id; 3333c3e85bdcSAkhil Goyal } 3334c3e85bdcSAkhil Goyal } 3335c3e85bdcSAkhil Goyal 3336fe3688baSAkhil Goyal static enum qman_cb_dqrr_result 3337fe3688baSAkhil Goyal dpaa_sec_process_parallel_event(void *event, 3338fe3688baSAkhil Goyal struct qman_portal *qm __always_unused, 3339fe3688baSAkhil Goyal struct qman_fq *outq, 3340fe3688baSAkhil Goyal const struct qm_dqrr_entry *dqrr, 3341fe3688baSAkhil Goyal void **bufs) 3342fe3688baSAkhil Goyal { 3343fe3688baSAkhil Goyal const struct qm_fd *fd; 3344fe3688baSAkhil Goyal struct dpaa_sec_job *job; 3345fe3688baSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 3346fe3688baSAkhil Goyal struct rte_event *ev = (struct rte_event *)event; 3347fe3688baSAkhil Goyal 3348fe3688baSAkhil Goyal fd = &dqrr->fd; 3349fe3688baSAkhil Goyal 3350fe3688baSAkhil Goyal /* sg is embedded in an op ctx, 3351fe3688baSAkhil Goyal * sg[0] is for output 3352fe3688baSAkhil Goyal * sg[1] for input 3353fe3688baSAkhil Goyal */ 3354ec861560SGagandeep Singh job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd)); 3355fe3688baSAkhil Goyal 3356fe3688baSAkhil Goyal ctx = container_of(job, struct dpaa_sec_op_ctx, job); 3357fe3688baSAkhil Goyal ctx->fd_status = fd->status; 3358fe3688baSAkhil Goyal if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) { 3359fe3688baSAkhil Goyal struct qm_sg_entry *sg_out; 3360fe3688baSAkhil Goyal uint32_t len; 3361fe3688baSAkhil Goyal 3362fe3688baSAkhil Goyal sg_out = &job->sg[0]; 3363fe3688baSAkhil Goyal hw_sg_to_cpu(sg_out); 3364fe3688baSAkhil Goyal len = sg_out->length; 3365fe3688baSAkhil Goyal ctx->op->sym->m_src->pkt_len = len; 3366fe3688baSAkhil Goyal ctx->op->sym->m_src->data_len = len; 3367fe3688baSAkhil Goyal } 3368fe3688baSAkhil Goyal if (!ctx->fd_status) { 3369fe3688baSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 3370fe3688baSAkhil Goyal } else { 3371fe3688baSAkhil Goyal DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status); 3372fe3688baSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR; 3373fe3688baSAkhil Goyal } 3374fe3688baSAkhil Goyal ev->event_ptr = (void *)ctx->op; 3375fe3688baSAkhil Goyal 3376fe3688baSAkhil Goyal ev->flow_id = outq->ev.flow_id; 3377fe3688baSAkhil Goyal ev->sub_event_type = outq->ev.sub_event_type; 3378fe3688baSAkhil Goyal ev->event_type = RTE_EVENT_TYPE_CRYPTODEV; 3379fe3688baSAkhil Goyal ev->op = RTE_EVENT_OP_NEW; 3380fe3688baSAkhil Goyal ev->sched_type = outq->ev.sched_type; 3381fe3688baSAkhil Goyal ev->queue_id = outq->ev.queue_id; 3382fe3688baSAkhil Goyal ev->priority = outq->ev.priority; 3383fe3688baSAkhil Goyal *bufs = (void *)ctx->op; 3384fe3688baSAkhil Goyal 3385fe3688baSAkhil Goyal rte_mempool_put(ctx->ctx_pool, (void *)ctx); 3386fe3688baSAkhil Goyal 3387fe3688baSAkhil Goyal return qman_cb_dqrr_consume; 3388fe3688baSAkhil Goyal } 3389fe3688baSAkhil Goyal 3390fe3688baSAkhil Goyal static enum qman_cb_dqrr_result 3391fe3688baSAkhil Goyal dpaa_sec_process_atomic_event(void *event, 3392fe3688baSAkhil Goyal struct qman_portal *qm __rte_unused, 3393fe3688baSAkhil Goyal struct qman_fq *outq, 3394fe3688baSAkhil Goyal const struct qm_dqrr_entry *dqrr, 3395fe3688baSAkhil Goyal void **bufs) 3396fe3688baSAkhil Goyal { 3397fe3688baSAkhil Goyal u8 index; 3398fe3688baSAkhil Goyal const struct qm_fd *fd; 3399fe3688baSAkhil Goyal struct dpaa_sec_job *job; 3400fe3688baSAkhil Goyal struct dpaa_sec_op_ctx *ctx; 3401fe3688baSAkhil Goyal struct rte_event *ev = (struct rte_event *)event; 3402fe3688baSAkhil Goyal 3403fe3688baSAkhil Goyal fd = &dqrr->fd; 3404fe3688baSAkhil Goyal 3405fe3688baSAkhil Goyal /* sg is embedded in an op ctx, 3406fe3688baSAkhil Goyal * sg[0] is for output 3407fe3688baSAkhil Goyal * sg[1] for input 3408fe3688baSAkhil Goyal */ 3409ec861560SGagandeep Singh job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd)); 3410fe3688baSAkhil Goyal 3411fe3688baSAkhil Goyal ctx = container_of(job, struct dpaa_sec_op_ctx, job); 3412fe3688baSAkhil Goyal ctx->fd_status = fd->status; 3413fe3688baSAkhil Goyal if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) { 3414fe3688baSAkhil Goyal struct qm_sg_entry *sg_out; 3415fe3688baSAkhil Goyal uint32_t len; 3416fe3688baSAkhil Goyal 3417fe3688baSAkhil Goyal sg_out = &job->sg[0]; 3418fe3688baSAkhil Goyal hw_sg_to_cpu(sg_out); 3419fe3688baSAkhil Goyal len = sg_out->length; 3420fe3688baSAkhil Goyal ctx->op->sym->m_src->pkt_len = len; 3421fe3688baSAkhil Goyal ctx->op->sym->m_src->data_len = len; 3422fe3688baSAkhil Goyal } 3423fe3688baSAkhil Goyal if (!ctx->fd_status) { 3424fe3688baSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 3425fe3688baSAkhil Goyal } else { 3426fe3688baSAkhil Goyal DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status); 3427fe3688baSAkhil Goyal ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR; 3428fe3688baSAkhil Goyal } 3429fe3688baSAkhil Goyal ev->event_ptr = (void *)ctx->op; 3430fe3688baSAkhil Goyal ev->flow_id = outq->ev.flow_id; 3431fe3688baSAkhil Goyal ev->sub_event_type = outq->ev.sub_event_type; 3432fe3688baSAkhil Goyal ev->event_type = RTE_EVENT_TYPE_CRYPTODEV; 3433fe3688baSAkhil Goyal ev->op = RTE_EVENT_OP_NEW; 3434fe3688baSAkhil Goyal ev->sched_type = outq->ev.sched_type; 3435fe3688baSAkhil Goyal ev->queue_id = outq->ev.queue_id; 3436fe3688baSAkhil Goyal ev->priority = outq->ev.priority; 3437fe3688baSAkhil Goyal 3438fe3688baSAkhil Goyal /* Save active dqrr entries */ 3439fe3688baSAkhil Goyal index = ((uintptr_t)dqrr >> 6) & (16/*QM_DQRR_SIZE*/ - 1); 3440fe3688baSAkhil Goyal DPAA_PER_LCORE_DQRR_SIZE++; 3441fe3688baSAkhil Goyal DPAA_PER_LCORE_DQRR_HELD |= 1 << index; 3442fe3688baSAkhil Goyal DPAA_PER_LCORE_DQRR_MBUF(index) = ctx->op->sym->m_src; 3443fe3688baSAkhil Goyal ev->impl_opaque = index + 1; 3444c9a1c2e5SDavid Marchand *dpaa_seqn(ctx->op->sym->m_src) = (uint32_t)index + 1; 3445fe3688baSAkhil Goyal *bufs = (void *)ctx->op; 3446fe3688baSAkhil Goyal 3447fe3688baSAkhil Goyal rte_mempool_put(ctx->ctx_pool, (void *)ctx); 3448fe3688baSAkhil Goyal 3449fe3688baSAkhil Goyal return qman_cb_dqrr_defer; 3450fe3688baSAkhil Goyal } 3451fe3688baSAkhil Goyal 3452fe3688baSAkhil Goyal int 3453fe3688baSAkhil Goyal dpaa_sec_eventq_attach(const struct rte_cryptodev *dev, 3454fe3688baSAkhil Goyal int qp_id, 3455fe3688baSAkhil Goyal uint16_t ch_id, 3456fe3688baSAkhil Goyal const struct rte_event *event) 3457fe3688baSAkhil Goyal { 3458fe3688baSAkhil Goyal struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id]; 3459fe3688baSAkhil Goyal struct qm_mcc_initfq opts = {0}; 3460fe3688baSAkhil Goyal 3461fe3688baSAkhil Goyal int ret; 3462fe3688baSAkhil Goyal 3463fe3688baSAkhil Goyal opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL | 3464fe3688baSAkhil Goyal QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB; 3465fe3688baSAkhil Goyal opts.fqd.dest.channel = ch_id; 3466fe3688baSAkhil Goyal 3467fe3688baSAkhil Goyal switch (event->sched_type) { 3468fe3688baSAkhil Goyal case RTE_SCHED_TYPE_ATOMIC: 3469fe3688baSAkhil Goyal opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE; 3470fe3688baSAkhil Goyal /* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary 3471fe3688baSAkhil Goyal * configuration with HOLD_ACTIVE setting 3472fe3688baSAkhil Goyal */ 3473fe3688baSAkhil Goyal opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK); 3474fe3688baSAkhil Goyal qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_atomic_event; 3475fe3688baSAkhil Goyal break; 3476fe3688baSAkhil Goyal case RTE_SCHED_TYPE_ORDERED: 3477*f665790aSDavid Marchand DPAA_SEC_ERR("Ordered queue schedule type is not supported"); 3478c08ced9aSAkhil Goyal return -ENOTSUP; 3479fe3688baSAkhil Goyal default: 3480fe3688baSAkhil Goyal opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK; 3481fe3688baSAkhil Goyal qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_parallel_event; 3482fe3688baSAkhil Goyal break; 3483fe3688baSAkhil Goyal } 3484fe3688baSAkhil Goyal 3485fe3688baSAkhil Goyal ret = qman_init_fq(&qp->outq, QMAN_INITFQ_FLAG_SCHED, &opts); 3486fe3688baSAkhil Goyal if (unlikely(ret)) { 3487fe3688baSAkhil Goyal DPAA_SEC_ERR("unable to init caam source fq!"); 3488fe3688baSAkhil Goyal return ret; 3489fe3688baSAkhil Goyal } 3490fe3688baSAkhil Goyal 3491fe3688baSAkhil Goyal memcpy(&qp->outq.ev, event, sizeof(struct rte_event)); 3492fe3688baSAkhil Goyal 3493fe3688baSAkhil Goyal return 0; 3494fe3688baSAkhil Goyal } 3495fe3688baSAkhil Goyal 3496fe3688baSAkhil Goyal int 3497fe3688baSAkhil Goyal dpaa_sec_eventq_detach(const struct rte_cryptodev *dev, 3498fe3688baSAkhil Goyal int qp_id) 3499fe3688baSAkhil Goyal { 3500fe3688baSAkhil Goyal struct qm_mcc_initfq opts = {0}; 3501fe3688baSAkhil Goyal int ret; 3502fe3688baSAkhil Goyal struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id]; 3503fe3688baSAkhil Goyal 3504fe3688baSAkhil Goyal opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL | 3505fe3688baSAkhil Goyal QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB; 3506fe3688baSAkhil Goyal qp->outq.cb.dqrr = dqrr_out_fq_cb_rx; 3507fe3688baSAkhil Goyal qp->outq.cb.ern = ern_sec_fq_handler; 3508fe3688baSAkhil Goyal qman_retire_fq(&qp->outq, NULL); 3509fe3688baSAkhil Goyal qman_oos_fq(&qp->outq); 3510fe3688baSAkhil Goyal ret = qman_init_fq(&qp->outq, 0, &opts); 3511fe3688baSAkhil Goyal if (ret) 3512a247fcd9SStephen Hemminger DPAA_SEC_ERR("Error in qman_init_fq: ret: %d", ret); 3513fe3688baSAkhil Goyal qp->outq.cb.dqrr = NULL; 3514fe3688baSAkhil Goyal 3515fe3688baSAkhil Goyal return ret; 3516fe3688baSAkhil Goyal } 3517fe3688baSAkhil Goyal 3518c3e85bdcSAkhil Goyal static struct rte_cryptodev_ops crypto_ops = { 3519c3e85bdcSAkhil Goyal .dev_configure = dpaa_sec_dev_configure, 3520c3e85bdcSAkhil Goyal .dev_start = dpaa_sec_dev_start, 3521c3e85bdcSAkhil Goyal .dev_stop = dpaa_sec_dev_stop, 3522c3e85bdcSAkhil Goyal .dev_close = dpaa_sec_dev_close, 3523c3e85bdcSAkhil Goyal .dev_infos_get = dpaa_sec_dev_infos_get, 3524c3e85bdcSAkhil Goyal .queue_pair_setup = dpaa_sec_queue_pair_setup, 3525c3e85bdcSAkhil Goyal .queue_pair_release = dpaa_sec_queue_pair_release, 3526012c5076SPablo de Lara .sym_session_get_size = dpaa_sec_sym_session_get_size, 3527012c5076SPablo de Lara .sym_session_configure = dpaa_sec_sym_session_configure, 35289d5f73c2SGagandeep Singh .sym_session_clear = dpaa_sec_sym_session_clear, 35299d5f73c2SGagandeep Singh /* Raw data-path API related operations */ 35309d5f73c2SGagandeep Singh .sym_get_raw_dp_ctx_size = dpaa_sec_get_dp_ctx_size, 35319d5f73c2SGagandeep Singh .sym_configure_raw_dp_ctx = dpaa_sec_configure_raw_dp_ctx, 3532c3e85bdcSAkhil Goyal }; 3533c3e85bdcSAkhil Goyal 35341f14d500SAkhil Goyal static const struct rte_security_capability * 35351f14d500SAkhil Goyal dpaa_sec_capabilities_get(void *device __rte_unused) 35361f14d500SAkhil Goyal { 35371f14d500SAkhil Goyal return dpaa_sec_security_cap; 35381f14d500SAkhil Goyal } 35391f14d500SAkhil Goyal 3540b74fd6b8SFerruh Yigit static const struct rte_security_ops dpaa_sec_security_ops = { 35411f14d500SAkhil Goyal .session_create = dpaa_sec_security_session_create, 35421f14d500SAkhil Goyal .session_update = NULL, 354366837861SAkhil Goyal .session_get_size = dpaa_sec_security_session_get_size, 35441f14d500SAkhil Goyal .session_stats_get = NULL, 35451f14d500SAkhil Goyal .session_destroy = dpaa_sec_security_session_destroy, 35461f14d500SAkhil Goyal .set_pkt_metadata = NULL, 35471f14d500SAkhil Goyal .capabilities_get = dpaa_sec_capabilities_get 35481f14d500SAkhil Goyal }; 354976c129ceSMaxime Coquelin 3550c3e85bdcSAkhil Goyal static int 3551c3e85bdcSAkhil Goyal dpaa_sec_uninit(struct rte_cryptodev *dev) 3552c3e85bdcSAkhil Goyal { 3553debef417SShreyansh Jain struct dpaa_sec_dev_private *internals; 3554c3e85bdcSAkhil Goyal 3555c3e85bdcSAkhil Goyal if (dev == NULL) 3556c3e85bdcSAkhil Goyal return -ENODEV; 3557c3e85bdcSAkhil Goyal 3558debef417SShreyansh Jain internals = dev->data->dev_private; 35591f14d500SAkhil Goyal rte_free(dev->security_ctx); 35601f14d500SAkhil Goyal 3561c3e85bdcSAkhil Goyal rte_free(internals); 3562c3e85bdcSAkhil Goyal 3563f163231eSHemant Agrawal DPAA_SEC_INFO("Closing DPAA_SEC device %s on numa socket %u", 3564c3e85bdcSAkhil Goyal dev->data->name, rte_socket_id()); 3565c3e85bdcSAkhil Goyal 3566c3e85bdcSAkhil Goyal return 0; 3567c3e85bdcSAkhil Goyal } 3568c3e85bdcSAkhil Goyal 3569c3e85bdcSAkhil Goyal static int 3570b1bbf222SGagandeep Singh check_devargs_handler(__rte_unused const char *key, const char *value, 3571b1bbf222SGagandeep Singh __rte_unused void *opaque) 3572b1bbf222SGagandeep Singh { 3573b1bbf222SGagandeep Singh dpaa_sec_dp_dump = atoi(value); 3574b1bbf222SGagandeep Singh if (dpaa_sec_dp_dump > DPAA_SEC_DP_FULL_DUMP) { 3575b1bbf222SGagandeep Singh DPAA_SEC_WARN("WARN: DPAA_SEC_DP_DUMP_LEVEL is not " 3576*f665790aSDavid Marchand "supported, changing to FULL error prints"); 3577b1bbf222SGagandeep Singh dpaa_sec_dp_dump = DPAA_SEC_DP_FULL_DUMP; 3578b1bbf222SGagandeep Singh } 3579b1bbf222SGagandeep Singh 3580b1bbf222SGagandeep Singh return 0; 3581b1bbf222SGagandeep Singh } 3582b1bbf222SGagandeep Singh 3583b1bbf222SGagandeep Singh static void 3584b1bbf222SGagandeep Singh dpaa_sec_get_devargs(struct rte_devargs *devargs, const char *key) 3585b1bbf222SGagandeep Singh { 3586b1bbf222SGagandeep Singh struct rte_kvargs *kvlist; 3587b1bbf222SGagandeep Singh 3588b1bbf222SGagandeep Singh if (!devargs) 3589b1bbf222SGagandeep Singh return; 3590b1bbf222SGagandeep Singh 3591b1bbf222SGagandeep Singh kvlist = rte_kvargs_parse(devargs->args, NULL); 3592b1bbf222SGagandeep Singh if (!kvlist) 3593b1bbf222SGagandeep Singh return; 3594b1bbf222SGagandeep Singh 3595b1bbf222SGagandeep Singh if (!rte_kvargs_count(kvlist, key)) { 3596b1bbf222SGagandeep Singh rte_kvargs_free(kvlist); 3597b1bbf222SGagandeep Singh return; 3598b1bbf222SGagandeep Singh } 3599b1bbf222SGagandeep Singh 3600b1bbf222SGagandeep Singh rte_kvargs_process(kvlist, key, 3601b1bbf222SGagandeep Singh check_devargs_handler, NULL); 3602b1bbf222SGagandeep Singh rte_kvargs_free(kvlist); 3603b1bbf222SGagandeep Singh } 3604b1bbf222SGagandeep Singh 3605b1bbf222SGagandeep Singh static int 3606c3e85bdcSAkhil Goyal dpaa_sec_dev_init(struct rte_cryptodev *cryptodev) 3607c3e85bdcSAkhil Goyal { 3608c3e85bdcSAkhil Goyal struct dpaa_sec_dev_private *internals; 36091f14d500SAkhil Goyal struct rte_security_ctx *security_instance; 3610c3e85bdcSAkhil Goyal struct dpaa_sec_qp *qp; 3611e79416d1SHemant Agrawal uint32_t i, flags; 3612c3e85bdcSAkhil Goyal int ret; 36138a3167dbSGagandeep Singh void *cmd_map; 36148a3167dbSGagandeep Singh int map_fd = -1; 3615c3e85bdcSAkhil Goyal 3616c3e85bdcSAkhil Goyal PMD_INIT_FUNC_TRACE(); 3617c3e85bdcSAkhil Goyal 36188a3167dbSGagandeep Singh internals = cryptodev->data->dev_private; 36198a3167dbSGagandeep Singh map_fd = open("/dev/mem", O_RDWR); 36208a3167dbSGagandeep Singh if (unlikely(map_fd < 0)) { 36218a3167dbSGagandeep Singh DPAA_SEC_ERR("Unable to open (/dev/mem)"); 36228a3167dbSGagandeep Singh return map_fd; 36238a3167dbSGagandeep Singh } 36248a3167dbSGagandeep Singh internals->sec_hw = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, 36258a3167dbSGagandeep Singh MAP_SHARED, map_fd, SEC_BASE_ADDR); 36268a3167dbSGagandeep Singh if (internals->sec_hw == MAP_FAILED) { 36278a3167dbSGagandeep Singh DPAA_SEC_ERR("Memory map failed"); 36288a3167dbSGagandeep Singh close(map_fd); 36298a3167dbSGagandeep Singh return -EINVAL; 36308a3167dbSGagandeep Singh } 36318a3167dbSGagandeep Singh cmd_map = (uint8_t *)internals->sec_hw + 36328a3167dbSGagandeep Singh (BLOCK_OFFSET * QI_BLOCK_NUMBER) + CMD_REG; 36338a3167dbSGagandeep Singh if (!(be32_to_cpu(rte_read32(cmd_map)) & QICTL_DQEN)) 36348a3167dbSGagandeep Singh /* enable QI interface */ 36358a3167dbSGagandeep Singh rte_write32(cpu_to_be32(QICTL_DQEN), cmd_map); 36368a3167dbSGagandeep Singh 36378a3167dbSGagandeep Singh ret = munmap(internals->sec_hw, MAP_SIZE); 36388a3167dbSGagandeep Singh if (ret) 3639*f665790aSDavid Marchand DPAA_SEC_WARN("munmap failed"); 36408a3167dbSGagandeep Singh 36418a3167dbSGagandeep Singh close(map_fd); 36429d5f73c2SGagandeep Singh cryptodev->driver_id = dpaa_cryptodev_driver_id; 3643c3e85bdcSAkhil Goyal cryptodev->dev_ops = &crypto_ops; 3644c3e85bdcSAkhil Goyal 3645c3e85bdcSAkhil Goyal cryptodev->enqueue_burst = dpaa_sec_enqueue_burst; 3646c3e85bdcSAkhil Goyal cryptodev->dequeue_burst = dpaa_sec_dequeue_burst; 3647c3e85bdcSAkhil Goyal cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO | 3648c3e85bdcSAkhil Goyal RTE_CRYPTODEV_FF_HW_ACCELERATED | 36491f14d500SAkhil Goyal RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING | 3650a74af788SAkhil Goyal RTE_CRYPTODEV_FF_SECURITY | 36519d5f73c2SGagandeep Singh RTE_CRYPTODEV_FF_SYM_RAW_DP | 36522717246eSPablo de Lara RTE_CRYPTODEV_FF_IN_PLACE_SGL | 36532717246eSPablo de Lara RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT | 36542717246eSPablo de Lara RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT | 36552717246eSPablo de Lara RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT | 36562717246eSPablo de Lara RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT; 3657c3e85bdcSAkhil Goyal 3658e79416d1SHemant Agrawal internals->max_nb_queue_pairs = RTE_DPAA_MAX_NB_SEC_QPS; 3659c3e85bdcSAkhil Goyal internals->max_nb_sessions = RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS; 3660c3e85bdcSAkhil Goyal 36611f14d500SAkhil Goyal /* 36621f14d500SAkhil Goyal * For secondary processes, we don't initialise any further as primary 36631f14d500SAkhil Goyal * has already done this work. Only check we don't need a different 36641f14d500SAkhil Goyal * RX function 36651f14d500SAkhil Goyal */ 36661f14d500SAkhil Goyal if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 3667f163231eSHemant Agrawal DPAA_SEC_WARN("Device already init by primary process"); 36681f14d500SAkhil Goyal return 0; 36691f14d500SAkhil Goyal } 36701f14d500SAkhil Goyal /* Initialize security_ctx only for primary process*/ 36711f14d500SAkhil Goyal security_instance = rte_malloc("rte_security_instances_ops", 36721f14d500SAkhil Goyal sizeof(struct rte_security_ctx), 0); 36731f14d500SAkhil Goyal if (security_instance == NULL) 36741f14d500SAkhil Goyal return -ENOMEM; 36751f14d500SAkhil Goyal security_instance->device = (void *)cryptodev; 36761f14d500SAkhil Goyal security_instance->ops = &dpaa_sec_security_ops; 36771f14d500SAkhil Goyal security_instance->sess_cnt = 0; 36781f14d500SAkhil Goyal cryptodev->security_ctx = security_instance; 36793b617ee7SAkhil Goyal rte_spinlock_init(&internals->lock); 3680c3e85bdcSAkhil Goyal for (i = 0; i < internals->max_nb_queue_pairs; i++) { 3681c3e85bdcSAkhil Goyal /* init qman fq for queue pair */ 3682c3e85bdcSAkhil Goyal qp = &internals->qps[i]; 3683c3e85bdcSAkhil Goyal ret = dpaa_sec_init_tx(&qp->outq); 3684c3e85bdcSAkhil Goyal if (ret) { 3685f163231eSHemant Agrawal DPAA_SEC_ERR("config tx of queue pair %d", i); 3686c3e85bdcSAkhil Goyal goto init_error; 3687c3e85bdcSAkhil Goyal } 3688e79416d1SHemant Agrawal } 3689e79416d1SHemant Agrawal 3690e79416d1SHemant Agrawal flags = QMAN_FQ_FLAG_LOCKED | QMAN_FQ_FLAG_DYNAMIC_FQID | 3691e79416d1SHemant Agrawal QMAN_FQ_FLAG_TO_DCPORTAL; 3692fd900d38SGagandeep Singh for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) { 3693e79416d1SHemant Agrawal /* create rx qman fq for sessions*/ 3694e79416d1SHemant Agrawal ret = qman_create_fq(0, flags, &internals->inq[i]); 3695e79416d1SHemant Agrawal if (unlikely(ret != 0)) { 3696f163231eSHemant Agrawal DPAA_SEC_ERR("sec qman_create_fq failed"); 3697c3e85bdcSAkhil Goyal goto init_error; 3698c3e85bdcSAkhil Goyal } 3699c3e85bdcSAkhil Goyal } 3700c3e85bdcSAkhil Goyal 3701b1bbf222SGagandeep Singh dpaa_sec_get_devargs(cryptodev->device->devargs, DRIVER_DUMP_MODE); 3702b1bbf222SGagandeep Singh 3703a247fcd9SStephen Hemminger DPAA_SEC_INFO("%s cryptodev init", cryptodev->data->name); 3704c3e85bdcSAkhil Goyal return 0; 3705c3e85bdcSAkhil Goyal 3706c3e85bdcSAkhil Goyal init_error: 3707*f665790aSDavid Marchand DPAA_SEC_ERR("driver %s: create failed", cryptodev->data->name); 3708c3e85bdcSAkhil Goyal 37092eaf352dSLukasz Wojciechowski rte_free(cryptodev->security_ctx); 3710c3e85bdcSAkhil Goyal return -EFAULT; 3711c3e85bdcSAkhil Goyal } 3712c3e85bdcSAkhil Goyal 3713c3e85bdcSAkhil Goyal static int 3714eb5a9a76SShreyansh Jain cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused, 3715c3e85bdcSAkhil Goyal struct rte_dpaa_device *dpaa_dev) 3716c3e85bdcSAkhil Goyal { 3717c3e85bdcSAkhil Goyal struct rte_cryptodev *cryptodev; 3718c3e85bdcSAkhil Goyal char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN]; 3719c3e85bdcSAkhil Goyal 3720c3e85bdcSAkhil Goyal int retval; 3721c3e85bdcSAkhil Goyal 372296ec64f1SVanshika Shukla if (rte_eal_process_type() != RTE_PROC_PRIMARY) 372396ec64f1SVanshika Shukla return 0; 372496ec64f1SVanshika Shukla 37250964a951SHemant Agrawal snprintf(cryptodev_name, sizeof(cryptodev_name), "%s", dpaa_dev->name); 3726c3e85bdcSAkhil Goyal 3727c3e85bdcSAkhil Goyal cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); 3728c3e85bdcSAkhil Goyal if (cryptodev == NULL) 3729c3e85bdcSAkhil Goyal return -ENOMEM; 3730c3e85bdcSAkhil Goyal 3731c3e85bdcSAkhil Goyal cryptodev->data->dev_private = rte_zmalloc_socket( 3732c3e85bdcSAkhil Goyal "cryptodev private structure", 3733c3e85bdcSAkhil Goyal sizeof(struct dpaa_sec_dev_private), 3734c3e85bdcSAkhil Goyal RTE_CACHE_LINE_SIZE, 3735c3e85bdcSAkhil Goyal rte_socket_id()); 3736c3e85bdcSAkhil Goyal 3737c3e85bdcSAkhil Goyal if (cryptodev->data->dev_private == NULL) 3738c3e85bdcSAkhil Goyal rte_panic("Cannot allocate memzone for private " 3739c3e85bdcSAkhil Goyal "device data"); 3740c3e85bdcSAkhil Goyal 3741c3e85bdcSAkhil Goyal dpaa_dev->crypto_dev = cryptodev; 3742c3e85bdcSAkhil Goyal cryptodev->device = &dpaa_dev->device; 3743c3e85bdcSAkhil Goyal 3744c3e85bdcSAkhil Goyal /* init user callbacks */ 3745c3e85bdcSAkhil Goyal TAILQ_INIT(&(cryptodev->link_intr_cbs)); 3746c3e85bdcSAkhil Goyal 3747c3e85bdcSAkhil Goyal /* if sec device version is not configured */ 3748c3e85bdcSAkhil Goyal if (!rta_get_sec_era()) { 3749c3e85bdcSAkhil Goyal const struct device_node *caam_node; 3750c3e85bdcSAkhil Goyal 3751c3e85bdcSAkhil Goyal for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") { 3752c3e85bdcSAkhil Goyal const uint32_t *prop = of_get_property(caam_node, 3753c3e85bdcSAkhil Goyal "fsl,sec-era", 3754c3e85bdcSAkhil Goyal NULL); 3755c3e85bdcSAkhil Goyal if (prop) { 3756c3e85bdcSAkhil Goyal rta_set_sec_era( 3757c3e85bdcSAkhil Goyal INTL_SEC_ERA(rte_cpu_to_be_32(*prop))); 3758c3e85bdcSAkhil Goyal break; 3759c3e85bdcSAkhil Goyal } 3760c3e85bdcSAkhil Goyal } 3761c3e85bdcSAkhil Goyal } 3762c3e85bdcSAkhil Goyal 3763e5872221SRohit Raj if (unlikely(!DPAA_PER_LCORE_PORTAL)) { 3764408077f2SHemant Agrawal retval = rte_dpaa_portal_init((void *)1); 3765408077f2SHemant Agrawal if (retval) { 3766408077f2SHemant Agrawal DPAA_SEC_ERR("Unable to initialize portal"); 37672eaf352dSLukasz Wojciechowski goto out; 3768408077f2SHemant Agrawal } 3769408077f2SHemant Agrawal } 3770408077f2SHemant Agrawal 3771c3e85bdcSAkhil Goyal /* Invoke PMD device initialization function */ 3772c3e85bdcSAkhil Goyal retval = dpaa_sec_dev_init(cryptodev); 3773d54c72ecSAkhil Goyal if (retval == 0) { 3774d54c72ecSAkhil Goyal rte_cryptodev_pmd_probing_finish(cryptodev); 3775c3e85bdcSAkhil Goyal return 0; 3776d54c72ecSAkhil Goyal } 3777c3e85bdcSAkhil Goyal 37782eaf352dSLukasz Wojciechowski retval = -ENXIO; 37792eaf352dSLukasz Wojciechowski out: 3780c3e85bdcSAkhil Goyal /* In case of error, cleanup is done */ 3781c3e85bdcSAkhil Goyal rte_free(cryptodev->data->dev_private); 3782c3e85bdcSAkhil Goyal 3783c3e85bdcSAkhil Goyal rte_cryptodev_pmd_release_device(cryptodev); 3784c3e85bdcSAkhil Goyal 37852eaf352dSLukasz Wojciechowski return retval; 3786c3e85bdcSAkhil Goyal } 3787c3e85bdcSAkhil Goyal 3788c3e85bdcSAkhil Goyal static int 3789c3e85bdcSAkhil Goyal cryptodev_dpaa_sec_remove(struct rte_dpaa_device *dpaa_dev) 3790c3e85bdcSAkhil Goyal { 3791c3e85bdcSAkhil Goyal struct rte_cryptodev *cryptodev; 3792c3e85bdcSAkhil Goyal int ret; 3793c3e85bdcSAkhil Goyal 3794c3e85bdcSAkhil Goyal cryptodev = dpaa_dev->crypto_dev; 3795c3e85bdcSAkhil Goyal if (cryptodev == NULL) 3796c3e85bdcSAkhil Goyal return -ENODEV; 3797c3e85bdcSAkhil Goyal 3798c3e85bdcSAkhil Goyal ret = dpaa_sec_uninit(cryptodev); 3799c3e85bdcSAkhil Goyal if (ret) 3800c3e85bdcSAkhil Goyal return ret; 3801c3e85bdcSAkhil Goyal 3802f2f020d2SDeclan Doherty return rte_cryptodev_pmd_destroy(cryptodev); 3803c3e85bdcSAkhil Goyal } 3804c3e85bdcSAkhil Goyal 3805c3e85bdcSAkhil Goyal static struct rte_dpaa_driver rte_dpaa_sec_driver = { 3806c3e85bdcSAkhil Goyal .drv_type = FSL_DPAA_CRYPTO, 3807c3e85bdcSAkhil Goyal .driver = { 3808c3e85bdcSAkhil Goyal .name = "DPAA SEC PMD" 3809c3e85bdcSAkhil Goyal }, 3810c3e85bdcSAkhil Goyal .probe = cryptodev_dpaa_sec_probe, 3811c3e85bdcSAkhil Goyal .remove = cryptodev_dpaa_sec_remove, 3812c3e85bdcSAkhil Goyal }; 3813c3e85bdcSAkhil Goyal 3814c3e85bdcSAkhil Goyal static struct cryptodev_driver dpaa_sec_crypto_drv; 3815c3e85bdcSAkhil Goyal 3816c3e85bdcSAkhil Goyal RTE_PMD_REGISTER_DPAA(CRYPTODEV_NAME_DPAA_SEC_PMD, rte_dpaa_sec_driver); 3817f737f5ceSFiona Trahe RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa_sec_crypto_drv, rte_dpaa_sec_driver.driver, 38189d5f73c2SGagandeep Singh dpaa_cryptodev_driver_id); 3819b1bbf222SGagandeep Singh RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_DPAA_SEC_PMD, 3820b1bbf222SGagandeep Singh DRIVER_DUMP_MODE "=<int>"); 38219c99878aSJerin Jacob RTE_LOG_REGISTER(dpaa_logtype_sec, pmd.crypto.dpaa, NOTICE); 3822