/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
- * Copyright 2016-2018 NXP
+ * Copyright 2016-2022 NXP
*
*/
#include <time.h>
#include <net/if.h>
+#include <unistd.h>
+#include <rte_ip.h>
#include <rte_mbuf.h>
#include <rte_cryptodev.h>
#include <rte_malloc.h>
#include <rte_cycles.h>
#include <rte_kvargs.h>
#include <rte_dev.h>
-#include <rte_cryptodev_pmd.h>
+#include <cryptodev_pmd.h>
#include <rte_common.h>
#include <rte_fslmc.h>
#include <fslmc_vfio.h>
#include <fsl_dpopr.h>
#include <fsl_dpseci.h>
#include <fsl_mc_sys.h>
+#include <rte_hexdump.h>
#include "dpaa2_sec_priv.h"
#include "dpaa2_sec_event.h"
#include "dpaa2_sec_logs.h"
-/* Required types */
-typedef uint64_t dma_addr_t;
-
/* RTA header files */
-#include <hw/desc/ipsec.h>
-#include <hw/desc/pdcp.h>
-#include <hw/desc/algo.h>
+#include <desc/ipsec.h>
+#include <desc/pdcp.h>
+#include <desc/sdap.h>
+#include <desc/algo.h>
/* Minimum job descriptor consists of a oneword job descriptor HEADER and
* a pointer to the shared descriptor
#define FSL_MC_DPSECI_DEVID 3
#define NO_PREFETCH 0
-/* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
-#define FLE_POOL_NUM_BUFS 32000
-#define FLE_POOL_BUF_SIZE 256
-#define FLE_POOL_CACHE_SIZE 512
-#define FLE_SG_MEM_SIZE 2048
-#define SEC_FLC_DHR_OUTBOUND -114
-#define SEC_FLC_DHR_INBOUND 0
-enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
+#define DRIVER_DUMP_MODE "drv_dump_mode"
+#define DRIVER_STRICT_ORDER "drv_strict_order"
+
+/* DPAA2_SEC_DP_DUMP levels */
+enum dpaa2_sec_dump_levels {
+ DPAA2_SEC_DP_NO_DUMP,
+ DPAA2_SEC_DP_ERR_DUMP,
+ DPAA2_SEC_DP_FULL_DUMP
+};
+
+uint8_t cryptodev_driver_id;
+uint8_t dpaa2_sec_dp_dump = DPAA2_SEC_DP_ERR_DUMP;
+
+static inline void
+free_fle(const struct qbman_fd *fd, struct dpaa2_sec_qp *qp)
+{
+ struct qbman_fle *fle;
+ struct rte_crypto_op *op;
+
+#ifdef RTE_LIB_SECURITY
+ if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
+ return;
+#endif
+ fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
+ op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
+ /* free the fle memory */
+ if (likely(rte_pktmbuf_is_contiguous(op->sym->m_src)))
+ rte_mempool_put(qp->fle_pool, (void *)(fle-1));
+ else
+ rte_free((void *)(fle-1));
+}
+
+#ifdef RTE_LIB_SECURITY
+static inline int
+build_proto_compound_sg_fd(dpaa2_sec_session *sess,
+ struct rte_crypto_op *op,
+ struct qbman_fd *fd, uint16_t bpid)
+{
+ struct rte_crypto_sym_op *sym_op = op->sym;
+ struct ctxt_priv *priv = sess->ctxt;
+ struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
+ struct sec_flow_context *flc;
+ struct rte_mbuf *mbuf;
+ uint32_t in_len = 0, out_len = 0;
+
+ if (sym_op->m_dst)
+ mbuf = sym_op->m_dst;
+ else
+ mbuf = sym_op->m_src;
+
+ /* first FLE entry used to store mbuf and session ctxt */
+ fle = (struct qbman_fle *)rte_malloc(NULL,
+ FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
+ RTE_CACHE_LINE_SIZE);
+ if (unlikely(!fle)) {
+ DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
+ return -ENOMEM;
+ }
+ memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
+ DPAA2_SET_FLE_ADDR(fle, (size_t)op);
+ DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
+
+ /* Save the shared descriptor */
+ flc = &priv->flc_desc[0].flc;
+
+ op_fle = fle + 1;
+ ip_fle = fle + 2;
+ sge = fle + 3;
+
+ if (likely(bpid < MAX_BPID)) {
+ DPAA2_SET_FD_BPID(fd, bpid);
+ DPAA2_SET_FLE_BPID(op_fle, bpid);
+ DPAA2_SET_FLE_BPID(ip_fle, bpid);
+ } else {
+ DPAA2_SET_FD_IVP(fd);
+ DPAA2_SET_FLE_IVP(op_fle);
+ DPAA2_SET_FLE_IVP(ip_fle);
+ }
+
+ /* Configure FD as a FRAME LIST */
+ DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
+ DPAA2_SET_FD_COMPOUND_FMT(fd);
+ DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
+
+ /* Configure Output FLE with Scatter/Gather Entry */
+ DPAA2_SET_FLE_SG_EXT(op_fle);
+ DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
+
+ /* Configure Output SGE for Encap/Decap */
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
+ /* o/p segs */
+ while (mbuf->next) {
+ sge->length = mbuf->data_len;
+ out_len += sge->length;
+ sge++;
+ mbuf = mbuf->next;
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
+ }
+ /* using buf_len for last buf - so that extra data can be added */
+ sge->length = mbuf->buf_len - mbuf->data_off;
+ out_len += sge->length;
+
+ DPAA2_SET_FLE_FIN(sge);
+ op_fle->length = out_len;
+
+ sge++;
+ mbuf = sym_op->m_src;
+
+ /* Configure Input FLE with Scatter/Gather Entry */
+ DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
+ DPAA2_SET_FLE_SG_EXT(ip_fle);
+ DPAA2_SET_FLE_FIN(ip_fle);
+
+ /* Configure input SGE for Encap/Decap */
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
+ sge->length = mbuf->data_len;
+ in_len += sge->length;
+
+ mbuf = mbuf->next;
+ /* i/p segs */
+ while (mbuf) {
+ sge++;
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
+ sge->length = mbuf->data_len;
+ in_len += sge->length;
+ mbuf = mbuf->next;
+ }
+ ip_fle->length = in_len;
+ DPAA2_SET_FLE_FIN(sge);
-static uint8_t cryptodev_driver_id;
+ /* In case of PDCP, per packet HFN is stored in
+ * mbuf priv after sym_op.
+ */
+ if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
+ uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
+ sess->pdcp.hfn_ovd_offset);
+ /*enable HFN override override */
+ DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
+ DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
+ DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
+ }
+ DPAA2_SET_FD_LEN(fd, ip_fle->length);
-int dpaa2_logtype_sec;
+ return 0;
+}
static inline int
build_proto_compound_fd(dpaa2_sec_session *sess,
struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct ctxt_priv *priv = sess->ctxt;
flc = &priv->flc_desc[0].flc;
/* we are using the first FLE entry to store Mbuf */
- retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
+ retval = rte_mempool_get(qp->fle_pool, (void **)(&fle));
if (retval) {
- DPAA2_SEC_ERR("Memory alloc failed");
- return -1;
+ DPAA2_SEC_DP_DEBUG("Proto: Memory alloc failed");
+ return -ENOMEM;
}
memset(fle, 0, FLE_POOL_BUF_SIZE);
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
/* Configure FD as a FRAME LIST */
DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
DPAA2_SET_FD_COMPOUND_FMT(fd);
- DPAA2_SET_FD_FLC(fd, (ptrdiff_t)flc);
+ DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
/* Configure Output FLE with dst mbuf data */
DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
DPAA2_SET_FD_LEN(fd, ip_fle->length);
DPAA2_SET_FLE_FIN(ip_fle);
-#ifdef ENABLE_HFN_OVERRIDE
+ /* In case of PDCP, per packet HFN is stored in
+ * mbuf priv after sym_op.
+ */
if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
+ uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
+ sess->pdcp.hfn_ovd_offset);
/*enable HFN override override */
- DPAA2_SET_FLE_INTERNAL_JD(ip_fle, sess->pdcp.hfn_ovd);
- DPAA2_SET_FLE_INTERNAL_JD(op_fle, sess->pdcp.hfn_ovd);
- DPAA2_SET_FD_INTERNAL_JD(fd, sess->pdcp.hfn_ovd);
+ DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
+ DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
+ DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
}
-#endif
return 0;
static inline int
build_proto_fd(dpaa2_sec_session *sess,
struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
if (sym_op->m_dst)
- return build_proto_compound_fd(sess, op, fd, bpid);
+ return build_proto_compound_fd(sess, op, fd, bpid, qp);
struct ctxt_priv *priv = sess->ctxt;
struct sec_flow_context *flc;
DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
- DPAA2_SET_FD_FLC(fd, (ptrdiff_t)flc);
+ DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
/* save physical address of mbuf */
op->sym->aead.digest.phys_addr = mbuf->buf_iova;
return 0;
}
+#endif
static inline int
build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
- PMD_INIT_FUNC_TRACE();
-
if (sym_op->m_dst)
mbuf = sym_op->m_dst;
else
mbuf = sym_op->m_src;
/* first FLE entry used to store mbuf and session ctxt */
- fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
+ fle = (struct qbman_fle *)rte_malloc(NULL,
+ FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
RTE_CACHE_LINE_SIZE);
if (unlikely(!fle)) {
DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
- return -1;
+ return -ENOMEM;
}
- memset(fle, 0, FLE_SG_MEM_SIZE);
+ memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
op_fle->length = (sess->dir == DIR_ENC) ?
- (sym_op->aead.data.length + icv_len + auth_only_len) :
- sym_op->aead.data.length + auth_only_len;
+ (sym_op->aead.data.length + icv_len) :
+ sym_op->aead.data.length;
/* Configure Output SGE for Encap/Decap */
DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
- DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset -
- auth_only_len);
- sge->length = mbuf->data_len - sym_op->aead.data.offset + auth_only_len;
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset);
+ sge->length = mbuf->data_len - sym_op->aead.data.offset;
mbuf = mbuf->next;
/* o/p segs */
static inline int
build_authenc_gcm_fd(dpaa2_sec_session *sess,
struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid,
+ struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct ctxt_priv *priv = sess->ctxt;
uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
- PMD_INIT_FUNC_TRACE();
-
if (sym_op->m_dst)
dst = sym_op->m_dst;
else
* to get the MBUF Addr from the previous FLE.
* We can have a better approach to use the inline Mbuf
*/
- retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
+ retval = rte_mempool_get(qp->fle_pool, (void **)(&fle));
if (retval) {
- DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
- return -1;
+ DPAA2_SEC_DP_DEBUG("GCM: no buffer available in fle pool");
+ return -ENOMEM;
}
memset(fle, 0, FLE_POOL_BUF_SIZE);
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
if (auth_only_len)
DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
fle->length = (sess->dir == DIR_ENC) ?
- (sym_op->aead.data.length + icv_len + auth_only_len) :
- sym_op->aead.data.length + auth_only_len;
+ (sym_op->aead.data.length + icv_len) :
+ sym_op->aead.data.length;
DPAA2_SET_FLE_SG_EXT(fle);
/* Configure Output SGE for Encap/Decap */
DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
- dst->data_off - auth_only_len);
- sge->length = sym_op->aead.data.length + auth_only_len;
+ DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
+ sge->length = sym_op->aead.data.length;
if (sess->dir == DIR_ENC) {
sge++;
DPAA2_SET_FLE_ADDR(sge,
DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
sge->length = sess->digest_length;
- DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
- sess->iv.length + auth_only_len));
}
DPAA2_SET_FLE_FIN(sge);
sess->digest_length);
DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
sge->length = sess->digest_length;
- DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
- sess->digest_length +
- sess->iv.length +
- auth_only_len));
}
DPAA2_SET_FLE_FIN(sge);
DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
}
+ DPAA2_SET_FD_LEN(fd, fle->length);
return 0;
}
struct ctxt_priv *priv = sess->ctxt;
struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
struct sec_flow_context *flc;
- uint32_t auth_only_len = sym_op->auth.data.length -
- sym_op->cipher.data.length;
+ uint16_t auth_hdr_len = sym_op->cipher.data.offset -
+ sym_op->auth.data.offset;
+ uint16_t auth_tail_len = sym_op->auth.data.length -
+ sym_op->cipher.data.length - auth_hdr_len;
+ uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
int icv_len = sess->digest_length;
uint8_t *old_icv;
struct rte_mbuf *mbuf;
uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
- PMD_INIT_FUNC_TRACE();
-
if (sym_op->m_dst)
mbuf = sym_op->m_dst;
else
mbuf = sym_op->m_src;
/* first FLE entry used to store mbuf and session ctxt */
- fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
+ fle = (struct qbman_fle *)rte_malloc(NULL,
+ FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
RTE_CACHE_LINE_SIZE);
if (unlikely(!fle)) {
DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
- return -1;
+ return -ENOMEM;
}
- memset(fle, 0, FLE_SG_MEM_SIZE);
+ memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
static inline int
build_authenc_fd(dpaa2_sec_session *sess,
struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct ctxt_priv *priv = sess->ctxt;
struct qbman_fle *fle, *sge;
struct sec_flow_context *flc;
- uint32_t auth_only_len = sym_op->auth.data.length -
- sym_op->cipher.data.length;
+ uint16_t auth_hdr_len = sym_op->cipher.data.offset -
+ sym_op->auth.data.offset;
+ uint16_t auth_tail_len = sym_op->auth.data.length -
+ sym_op->cipher.data.length - auth_hdr_len;
+ uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
+
int icv_len = sess->digest_length, retval;
uint8_t *old_icv;
uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
struct rte_mbuf *dst;
- PMD_INIT_FUNC_TRACE();
-
if (sym_op->m_dst)
dst = sym_op->m_dst;
else
* to get the MBUF Addr from the previous FLE.
* We can have a better approach to use the inline Mbuf
*/
- retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
+ retval = rte_mempool_get(qp->fle_pool, (void **)(&fle));
if (retval) {
- DPAA2_SEC_ERR("Memory alloc failed for SGE");
- return -1;
+ DPAA2_SEC_DP_DEBUG("AUTHENC: no buffer available in fle pool");
+ return -ENOMEM;
}
memset(fle, 0, FLE_POOL_BUF_SIZE);
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
struct sec_flow_context *flc;
struct ctxt_priv *priv = sess->ctxt;
+ int data_len, data_offset;
uint8_t *old_digest;
struct rte_mbuf *mbuf;
- PMD_INIT_FUNC_TRACE();
+ data_len = sym_op->auth.data.length;
+ data_offset = sym_op->auth.data.offset;
+
+ if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
+ sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+ if ((data_len & 7) || (data_offset & 7)) {
+ DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
+ return -ENOTSUP;
+ }
+
+ data_len = data_len >> 3;
+ data_offset = data_offset >> 3;
+ }
mbuf = sym_op->m_src;
- fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
+ fle = (struct qbman_fle *)rte_malloc(NULL,
+ FLE_SG_MEM_SIZE(mbuf->nb_segs),
RTE_CACHE_LINE_SIZE);
if (unlikely(!fle)) {
DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
- return -1;
+ return -ENOMEM;
}
- memset(fle, 0, FLE_SG_MEM_SIZE);
+ memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
/* first FLE entry used to store mbuf and session ctxt */
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
/* i/p fle */
DPAA2_SET_FLE_SG_EXT(ip_fle);
DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
- /* i/p 1st seg */
- DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset + mbuf->data_off);
- sge->length = mbuf->data_len - sym_op->auth.data.offset;
+ ip_fle->length = data_len;
- /* i/p segs */
- mbuf = mbuf->next;
- while (mbuf) {
+ if (sess->iv.length) {
+ uint8_t *iv_ptr;
+
+ iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
+ sess->iv.offset);
+
+ if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
+ iv_ptr = conv_to_snow_f9_iv(iv_ptr);
+ sge->length = 12;
+ } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+ iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
+ sge->length = 8;
+ } else {
+ sge->length = sess->iv.length;
+ }
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
+ ip_fle->length += sge->length;
sge++;
- DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
- DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
- sge->length = mbuf->data_len;
- mbuf = mbuf->next;
}
- if (sess->dir == DIR_ENC) {
- /* Digest calculation case */
- sge->length -= sess->digest_length;
- ip_fle->length = sym_op->auth.data.length;
+ /* i/p 1st seg */
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
+
+ if (data_len <= (mbuf->data_len - data_offset)) {
+ sge->length = data_len;
+ data_len = 0;
} else {
+ sge->length = mbuf->data_len - data_offset;
+
+ /* remaining i/p segs */
+ while ((data_len = data_len - sge->length) &&
+ (mbuf = mbuf->next)) {
+ sge++;
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
+ DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
+ if (data_len > mbuf->data_len)
+ sge->length = mbuf->data_len;
+ else
+ sge->length = data_len;
+ }
+ }
+
+ if (sess->dir == DIR_DEC) {
/* Digest verification case */
sge++;
old_digest = (uint8_t *)(sge + 1);
sess->digest_length);
DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
sge->length = sess->digest_length;
- ip_fle->length = sym_op->auth.data.length +
- sess->digest_length;
+ ip_fle->length += sess->digest_length;
}
DPAA2_SET_FLE_FIN(sge);
DPAA2_SET_FLE_FIN(ip_fle);
static inline int
build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct qbman_fle *fle, *sge;
struct sec_flow_context *flc;
struct ctxt_priv *priv = sess->ctxt;
+ int data_len, data_offset;
uint8_t *old_digest;
int retval;
- PMD_INIT_FUNC_TRACE();
+ data_len = sym_op->auth.data.length;
+ data_offset = sym_op->auth.data.offset;
+
+ if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
+ sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+ if ((data_len & 7) || (data_offset & 7)) {
+ DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
+ return -ENOTSUP;
+ }
+
+ data_len = data_len >> 3;
+ data_offset = data_offset >> 3;
+ }
- retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
+ retval = rte_mempool_get(qp->fle_pool, (void **)(&fle));
if (retval) {
- DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
- return -1;
+ DPAA2_SEC_DP_DEBUG("AUTH: no buffer available in fle pool");
+ return -ENOMEM;
}
memset(fle, 0, FLE_POOL_BUF_SIZE);
/* TODO we are using the first FLE entry to store Mbuf.
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
fle = fle + 1;
+ sge = fle + 2;
if (likely(bpid < MAX_BPID)) {
DPAA2_SET_FD_BPID(fd, bpid);
DPAA2_SET_FLE_BPID(fle, bpid);
DPAA2_SET_FLE_BPID(fle + 1, bpid);
+ DPAA2_SET_FLE_BPID(sge, bpid);
+ DPAA2_SET_FLE_BPID(sge + 1, bpid);
} else {
DPAA2_SET_FD_IVP(fd);
DPAA2_SET_FLE_IVP(fle);
DPAA2_SET_FLE_IVP((fle + 1));
+ DPAA2_SET_FLE_IVP(sge);
+ DPAA2_SET_FLE_IVP((sge + 1));
}
+
flc = &priv->flc_desc[DESC_INITFINAL].flc;
DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
+ DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
+ DPAA2_SET_FD_COMPOUND_FMT(fd);
DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
fle->length = sess->digest_length;
-
- DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
- DPAA2_SET_FD_COMPOUND_FMT(fd);
fle++;
- if (sess->dir == DIR_ENC) {
- DPAA2_SET_FLE_ADDR(fle,
- DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
- DPAA2_SET_FLE_OFFSET(fle, sym_op->auth.data.offset +
- sym_op->m_src->data_off);
- DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length);
- fle->length = sym_op->auth.data.length;
- } else {
- sge = fle + 2;
- DPAA2_SET_FLE_SG_EXT(fle);
- DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
+ /* Setting input FLE */
+ DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
+ DPAA2_SET_FLE_SG_EXT(fle);
+ fle->length = data_len;
- if (likely(bpid < MAX_BPID)) {
- DPAA2_SET_FLE_BPID(sge, bpid);
- DPAA2_SET_FLE_BPID(sge + 1, bpid);
+ if (sess->iv.length) {
+ uint8_t *iv_ptr;
+
+ iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
+ sess->iv.offset);
+
+ if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
+ iv_ptr = conv_to_snow_f9_iv(iv_ptr);
+ sge->length = 12;
+ } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+ iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
+ sge->length = 8;
} else {
- DPAA2_SET_FLE_IVP(sge);
- DPAA2_SET_FLE_IVP((sge + 1));
+ sge->length = sess->iv.length;
}
- DPAA2_SET_FLE_ADDR(sge,
- DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
- sym_op->m_src->data_off);
- DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length +
- sess->digest_length);
- sge->length = sym_op->auth.data.length;
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
+ fle->length = fle->length + sge->length;
+ sge++;
+ }
+
+ /* Setting data to authenticate */
+ DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
+ DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
+ sge->length = data_len;
+
+ if (sess->dir == DIR_DEC) {
sge++;
old_digest = (uint8_t *)(sge + 1);
rte_memcpy(old_digest, sym_op->auth.digest.data,
sess->digest_length);
DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
sge->length = sess->digest_length;
- fle->length = sym_op->auth.data.length +
- sess->digest_length;
- DPAA2_SET_FLE_FIN(sge);
+ fle->length = fle->length + sess->digest_length;
}
+
+ DPAA2_SET_FLE_FIN(sge);
DPAA2_SET_FLE_FIN(fle);
+ DPAA2_SET_FD_LEN(fd, fle->length);
return 0;
}
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
+ int data_len, data_offset;
struct sec_flow_context *flc;
struct ctxt_priv *priv = sess->ctxt;
struct rte_mbuf *mbuf;
uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
- PMD_INIT_FUNC_TRACE();
+ data_len = sym_op->cipher.data.length;
+ data_offset = sym_op->cipher.data.offset;
+
+ if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
+ sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
+ if ((data_len & 7) || (data_offset & 7)) {
+ DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
+ return -ENOTSUP;
+ }
+
+ data_len = data_len >> 3;
+ data_offset = data_offset >> 3;
+ }
if (sym_op->m_dst)
mbuf = sym_op->m_dst;
else
mbuf = sym_op->m_src;
- fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
+ /* first FLE entry used to store mbuf and session ctxt */
+ fle = (struct qbman_fle *)rte_malloc(NULL,
+ FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
RTE_CACHE_LINE_SIZE);
if (!fle) {
DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
- return -1;
+ return -ENOMEM;
}
- memset(fle, 0, FLE_SG_MEM_SIZE);
+ memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
/* first FLE entry used to store mbuf and session ctxt */
DPAA2_SET_FLE_ADDR(fle, (size_t)op);
DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
DPAA2_SEC_DP_DEBUG(
"CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
" data_off: 0x%x\n",
- sym_op->cipher.data.offset,
- sym_op->cipher.data.length,
+ data_offset,
+ data_len,
sess->iv.length,
sym_op->m_src->data_off);
/* o/p fle */
DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
- op_fle->length = sym_op->cipher.data.length;
+ op_fle->length = data_len;
DPAA2_SET_FLE_SG_EXT(op_fle);
/* o/p 1st seg */
DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset + mbuf->data_off);
- sge->length = mbuf->data_len - sym_op->cipher.data.offset;
+ DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
+ sge->length = mbuf->data_len - data_offset;
mbuf = mbuf->next;
/* o/p segs */
mbuf = sym_op->m_src;
sge++;
DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
- ip_fle->length = sess->iv.length + sym_op->cipher.data.length;
+ ip_fle->length = sess->iv.length + data_len;
DPAA2_SET_FLE_SG_EXT(ip_fle);
/* i/p IV */
/* i/p 1st seg */
DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
- mbuf->data_off);
- sge->length = mbuf->data_len - sym_op->cipher.data.offset;
+ DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
+ sge->length = mbuf->data_len - data_offset;
mbuf = mbuf->next;
/* i/p segs */
static int
build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
struct rte_crypto_sym_op *sym_op = op->sym;
struct qbman_fle *fle, *sge;
- int retval;
+ int retval, data_len, data_offset;
struct sec_flow_context *flc;
struct ctxt_priv *priv = sess->ctxt;
uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
sess->iv.offset);
struct rte_mbuf *dst;
- PMD_INIT_FUNC_TRACE();
+ data_len = sym_op->cipher.data.length;
+ data_offset = sym_op->cipher.data.offset;
+
+ if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
+ sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
+ if ((data_len & 7) || (data_offset & 7)) {
+ DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
+ return -ENOTSUP;
+ }
+
+ data_len = data_len >> 3;
+ data_offset = data_offset >> 3;
+ }
if (sym_op->m_dst)
dst = sym_op->m_dst;
else
dst = sym_op->m_src;
- retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
+ retval = rte_mempool_get(qp->fle_pool, (void **)(&fle));
if (retval) {
- DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
- return -1;
+ DPAA2_SEC_DP_DEBUG("CIPHER: no buffer available in fle pool");
+ return -ENOMEM;
}
memset(fle, 0, FLE_POOL_BUF_SIZE);
/* TODO we are using the first FLE entry to store Mbuf.
flc = &priv->flc_desc[0].flc;
DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
- DPAA2_SET_FD_LEN(fd, sym_op->cipher.data.length +
- sess->iv.length);
+ DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
DPAA2_SET_FD_COMPOUND_FMT(fd);
DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
DPAA2_SEC_DP_DEBUG(
"CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
" data_off: 0x%x\n",
- sym_op->cipher.data.offset,
- sym_op->cipher.data.length,
+ data_offset,
+ data_len,
sess->iv.length,
sym_op->m_src->data_off);
DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
- DPAA2_SET_FLE_OFFSET(fle, sym_op->cipher.data.offset +
- dst->data_off);
+ DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
- fle->length = sym_op->cipher.data.length + sess->iv.length;
+ fle->length = data_len + sess->iv.length;
DPAA2_SEC_DP_DEBUG(
"CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
fle++;
DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
- fle->length = sym_op->cipher.data.length + sess->iv.length;
+ fle->length = data_len + sess->iv.length;
DPAA2_SET_FLE_SG_EXT(fle);
sge++;
DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
- DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
- sym_op->m_src->data_off);
+ DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
- sge->length = sym_op->cipher.data.length;
+ sge->length = data_len;
DPAA2_SET_FLE_FIN(sge);
DPAA2_SET_FLE_FIN(fle);
static inline int
build_sec_fd(struct rte_crypto_op *op,
- struct qbman_fd *fd, uint16_t bpid)
+ struct qbman_fd *fd, uint16_t bpid, struct dpaa2_sec_qp *qp)
{
int ret = -1;
dpaa2_sec_session *sess;
- PMD_INIT_FUNC_TRACE();
-
if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
sess = (dpaa2_sec_session *)get_sym_session_private_data(
op->sym->session, cryptodev_driver_id);
+#ifdef RTE_LIB_SECURITY
else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
sess = (dpaa2_sec_session *)get_sec_session_private_data(
op->sym->sec_session);
- else
- return -1;
+#endif
+ else {
+ DPAA2_SEC_DP_ERR("Session type invalid\n");
+ return -ENOTSUP;
+ }
+
+ if (!sess) {
+ DPAA2_SEC_DP_ERR("Session not available\n");
+ return -EINVAL;
+ }
- /* Segmented buffer */
- if (unlikely(!rte_pktmbuf_is_contiguous(op->sym->m_src))) {
+ /* Any of the buffer is segmented*/
+ if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
+ ((op->sym->m_dst != NULL) &&
+ !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
switch (sess->ctxt_type) {
case DPAA2_SEC_CIPHER:
ret = build_cipher_sg_fd(sess, op, fd, bpid);
case DPAA2_SEC_CIPHER_HASH:
ret = build_authenc_sg_fd(sess, op, fd, bpid);
break;
+#ifdef RTE_LIB_SECURITY
+ case DPAA2_SEC_IPSEC:
+ case DPAA2_SEC_PDCP:
+ ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
+ break;
+#endif
case DPAA2_SEC_HASH_CIPHER:
default:
DPAA2_SEC_ERR("error: Unsupported session");
} else {
switch (sess->ctxt_type) {
case DPAA2_SEC_CIPHER:
- ret = build_cipher_fd(sess, op, fd, bpid);
+ ret = build_cipher_fd(sess, op, fd, bpid, qp);
break;
case DPAA2_SEC_AUTH:
- ret = build_auth_fd(sess, op, fd, bpid);
+ ret = build_auth_fd(sess, op, fd, bpid, qp);
break;
case DPAA2_SEC_AEAD:
- ret = build_authenc_gcm_fd(sess, op, fd, bpid);
+ ret = build_authenc_gcm_fd(sess, op, fd, bpid, qp);
break;
case DPAA2_SEC_CIPHER_HASH:
- ret = build_authenc_fd(sess, op, fd, bpid);
+ ret = build_authenc_fd(sess, op, fd, bpid, qp);
break;
+#ifdef RTE_LIB_SECURITY
case DPAA2_SEC_IPSEC:
- ret = build_proto_fd(sess, op, fd, bpid);
+ ret = build_proto_fd(sess, op, fd, bpid, qp);
break;
case DPAA2_SEC_PDCP:
- ret = build_proto_compound_fd(sess, op, fd, bpid);
+ ret = build_proto_compound_fd(sess, op, fd, bpid, qp);
break;
+#endif
case DPAA2_SEC_HASH_CIPHER:
default:
DPAA2_SEC_ERR("error: Unsupported session");
+ ret = -ENOTSUP;
}
}
return ret;
uint32_t loop;
int32_t ret;
struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
- uint32_t frames_to_send;
+ uint32_t frames_to_send, retry_count;
struct qbman_eq_desc eqdesc;
struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
struct qbman_swp *swp;
if (!DPAA2_PER_LCORE_DPIO) {
ret = dpaa2_affine_qbman_swp();
if (ret) {
- DPAA2_SEC_ERR("Failure in affining portal");
+ DPAA2_SEC_ERR(
+ "Failed to allocate IO portal, tid: %d\n",
+ rte_gettid());
return 0;
}
}
dpaa2_eqcr_size : nb_ops;
for (loop = 0; loop < frames_to_send; loop++) {
- if ((*ops)->sym->m_src->seqn) {
- uint8_t dqrr_index = (*ops)->sym->m_src->seqn - 1;
-
- flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
- DPAA2_PER_LCORE_DQRR_SIZE--;
- DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
- (*ops)->sym->m_src->seqn = DPAA2_INVALID_MBUF_SEQN;
+ if (*dpaa2_seqn((*ops)->sym->m_src)) {
+ if (*dpaa2_seqn((*ops)->sym->m_src) & QBMAN_ENQUEUE_FLAG_DCA) {
+ DPAA2_PER_LCORE_DQRR_SIZE--;
+ DPAA2_PER_LCORE_DQRR_HELD &= ~(1 <<
+ *dpaa2_seqn((*ops)->sym->m_src) &
+ QBMAN_EQCR_DCA_IDXMASK);
+ }
+ flags[loop] = *dpaa2_seqn((*ops)->sym->m_src);
+ *dpaa2_seqn((*ops)->sym->m_src) = DPAA2_INVALID_MBUF_SEQN;
}
/*Clear the unused FD fields before sending*/
memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
mb_pool = (*ops)->sym->m_src->pool;
bpid = mempool_to_bpid(mb_pool);
- ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
+ ret = build_sec_fd(*ops, &fd_arr[loop], bpid, dpaa2_qp);
if (ret) {
- DPAA2_SEC_ERR("error: Improper packet contents"
- " for crypto operation");
+ DPAA2_SEC_DP_DEBUG("FD build failed\n");
goto skip_tx;
}
ops++;
}
+
loop = 0;
+ retry_count = 0;
while (loop < frames_to_send) {
- loop += qbman_swp_enqueue_multiple(swp, &eqdesc,
- &fd_arr[loop],
- &flags[loop],
- frames_to_send - loop);
+ ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
+ &fd_arr[loop],
+ &flags[loop],
+ frames_to_send - loop);
+ if (unlikely(ret < 0)) {
+ retry_count++;
+ if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
+ num_tx += loop;
+ nb_ops -= loop;
+ DPAA2_SEC_DP_DEBUG("Enqueue fail\n");
+ /* freeing the fle buffers */
+ while (loop < frames_to_send) {
+ free_fle(&fd_arr[loop],
+ dpaa2_qp);
+ loop++;
+ }
+ goto skip_tx;
+ }
+ } else {
+ loop += ret;
+ retry_count = 0;
+ }
}
- num_tx += frames_to_send;
- nb_ops -= frames_to_send;
+ num_tx += loop;
+ nb_ops -= loop;
}
skip_tx:
dpaa2_qp->tx_vq.tx_pkts += num_tx;
return num_tx;
}
+#ifdef RTE_LIB_SECURITY
static inline struct rte_crypto_op *
-sec_simple_fd_to_mbuf(const struct qbman_fd *fd, __rte_unused uint8_t id)
+sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
{
struct rte_crypto_op *op;
uint16_t len = DPAA2_GET_FD_LEN(fd);
- uint16_t diff = 0;
- dpaa2_sec_session *sess_priv;
+ int16_t diff = 0;
+ dpaa2_sec_session *sess_priv __rte_unused;
+ if (unlikely(DPAA2_GET_FD_IVP(fd))) {
+ DPAA2_SEC_ERR("error: non inline buffer");
+ return NULL;
+ }
struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
else
mbuf->data_off += SEC_FLC_DHR_INBOUND;
+ if (unlikely(fd->simple.frc)) {
+ DPAA2_SEC_ERR("SEC returned Error - %x",
+ fd->simple.frc);
+ op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+ } else {
+ op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
+ }
+
return op;
}
+#endif
static inline struct rte_crypto_op *
-sec_fd_to_mbuf(const struct qbman_fd *fd, uint8_t driver_id)
+sec_fd_to_mbuf(const struct qbman_fd *fd, struct dpaa2_sec_qp *qp)
{
struct qbman_fle *fle;
struct rte_crypto_op *op;
- struct ctxt_priv *priv;
struct rte_mbuf *dst, *src;
+#ifdef RTE_LIB_SECURITY
if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
- return sec_simple_fd_to_mbuf(fd, driver_id);
-
+ return sec_simple_fd_to_mbuf(fd);
+#endif
fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
* We can have a better approach to use the inline Mbuf
*/
- if (unlikely(DPAA2_GET_FD_IVP(fd))) {
- /* TODO complete it. */
- DPAA2_SEC_ERR("error: non inline buffer");
- return NULL;
- }
op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
/* Prefeth op */
} else
dst = src;
+#ifdef RTE_LIB_SECURITY
if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
- dpaa2_sec_session *sess = (dpaa2_sec_session *)
- get_sec_session_private_data(op->sym->sec_session);
- if (sess->ctxt_type == DPAA2_SEC_IPSEC) {
- uint16_t len = DPAA2_GET_FD_LEN(fd);
- dst->pkt_len = len;
- dst->data_len = len;
+ uint16_t len = DPAA2_GET_FD_LEN(fd);
+ dst->pkt_len = len;
+ while (dst->next != NULL) {
+ len -= dst->data_len;
+ dst = dst->next;
}
+ dst->data_len = len;
}
-
+#endif
DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
" fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
(void *)dst,
/* free the fle memory */
if (likely(rte_pktmbuf_is_contiguous(src))) {
- priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
- rte_mempool_put(priv->fle_pool, (void *)(fle-1));
+ rte_mempool_put(qp->fle_pool, (void *)(fle-1));
} else
rte_free((void *)(fle-1));
return op;
}
-static uint16_t
+static void
+dpaa2_sec_dump(struct rte_crypto_op *op)
+{
+ int i;
+ dpaa2_sec_session *sess = NULL;
+ struct ctxt_priv *priv;
+ uint8_t bufsize;
+ struct rte_crypto_sym_op *sym_op;
+
+ if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
+ sess = (dpaa2_sec_session *)get_sym_session_private_data(
+ op->sym->session, cryptodev_driver_id);
+#ifdef RTE_LIBRTE_SECURITY
+ else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
+ sess = (dpaa2_sec_session *)get_sec_session_private_data(
+ op->sym->sec_session);
+#endif
+
+ if (sess == NULL)
+ goto mbuf_dump;
+
+ priv = (struct ctxt_priv *)sess->ctxt;
+ printf("\n****************************************\n"
+ "session params:\n\tContext type:\t%d\n\tDirection:\t%s\n"
+ "\tCipher alg:\t%d\n\tAuth alg:\t%d\n\tAead alg:\t%d\n"
+ "\tCipher key len:\t%zd\n", sess->ctxt_type,
+ (sess->dir == DIR_ENC) ? "DIR_ENC" : "DIR_DEC",
+ sess->cipher_alg, sess->auth_alg, sess->aead_alg,
+ sess->cipher_key.length);
+ rte_hexdump(stdout, "cipher key", sess->cipher_key.data,
+ sess->cipher_key.length);
+ rte_hexdump(stdout, "auth key", sess->auth_key.data,
+ sess->auth_key.length);
+ printf("\tAuth key len:\t%zd\n\tIV len:\t\t%d\n\tIV offset:\t%d\n"
+ "\tdigest length:\t%d\n\tstatus:\t\t%d\n\taead auth only"
+ " len:\t%d\n\taead cipher text:\t%d\n",
+ sess->auth_key.length, sess->iv.length, sess->iv.offset,
+ sess->digest_length, sess->status,
+ sess->ext_params.aead_ctxt.auth_only_len,
+ sess->ext_params.aead_ctxt.auth_cipher_text);
+#ifdef RTE_LIBRTE_SECURITY
+ printf("PDCP session params:\n"
+ "\tDomain:\t\t%d\n\tBearer:\t\t%d\n\tpkt_dir:\t%d\n\thfn_ovd:"
+ "\t%d\n\tsn_size:\t%d\n\thfn_ovd_offset:\t%d\n\thfn:\t\t%d\n"
+ "\thfn_threshold:\t0x%x\n", sess->pdcp.domain,
+ sess->pdcp.bearer, sess->pdcp.pkt_dir, sess->pdcp.hfn_ovd,
+ sess->pdcp.sn_size, sess->pdcp.hfn_ovd_offset, sess->pdcp.hfn,
+ sess->pdcp.hfn_threshold);
+
+#endif
+ bufsize = (uint8_t)priv->flc_desc[0].flc.word1_sdl;
+ printf("Descriptor Dump:\n");
+ for (i = 0; i < bufsize; i++)
+ printf("\tDESC[%d]:0x%x\n", i, priv->flc_desc[0].desc[i]);
+
+ printf("\n");
+mbuf_dump:
+ sym_op = op->sym;
+ if (sym_op->m_src) {
+ printf("Source mbuf:\n");
+ rte_pktmbuf_dump(stdout, sym_op->m_src, sym_op->m_src->data_len);
+ }
+ if (sym_op->m_dst) {
+ printf("Destination mbuf:\n");
+ rte_pktmbuf_dump(stdout, sym_op->m_dst, sym_op->m_dst->data_len);
+ }
+
+ printf("Session address = %p\ncipher offset: %d, length: %d\n"
+ "auth offset: %d, length: %d\n aead offset: %d, length: %d\n"
+ , sym_op->session,
+ sym_op->cipher.data.offset, sym_op->cipher.data.length,
+ sym_op->auth.data.offset, sym_op->auth.data.length,
+ sym_op->aead.data.offset, sym_op->aead.data.length);
+ printf("\n");
+
+}
+
+static void
+dpaa2_sec_free_eqresp_buf(uint16_t eqresp_ci,
+ struct dpaa2_queue *dpaa2_q)
+{
+ struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
+ struct rte_crypto_op *op;
+ struct qbman_fd *fd;
+ struct dpaa2_sec_qp *dpaa2_qp;
+
+ dpaa2_qp = container_of(dpaa2_q, struct dpaa2_sec_qp, tx_vq);
+ fd = qbman_result_eqresp_fd(&dpio_dev->eqresp[eqresp_ci]);
+ op = sec_fd_to_mbuf(fd, dpaa2_qp);
+ /* Instead of freeing, enqueue it to the sec tx queue (sec->core)
+ * after setting an error in FD. But this will have performance impact.
+ */
+ rte_pktmbuf_free(op->sym->m_src);
+}
+
+static void
+dpaa2_sec_set_enqueue_descriptor(struct dpaa2_queue *dpaa2_q,
+ struct rte_mbuf *m,
+ struct qbman_eq_desc *eqdesc)
+{
+ struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
+ struct eqresp_metadata *eqresp_meta;
+ struct dpaa2_sec_dev_private *priv = dpaa2_q->crypto_data->dev_private;
+ uint16_t orpid, seqnum;
+ uint8_t dq_idx;
+
+ if (*dpaa2_seqn(m) & DPAA2_ENQUEUE_FLAG_ORP) {
+ orpid = (*dpaa2_seqn(m) & DPAA2_EQCR_OPRID_MASK) >>
+ DPAA2_EQCR_OPRID_SHIFT;
+ seqnum = (*dpaa2_seqn(m) & DPAA2_EQCR_SEQNUM_MASK) >>
+ DPAA2_EQCR_SEQNUM_SHIFT;
+
+
+ if (!priv->en_loose_ordered) {
+ qbman_eq_desc_set_orp(eqdesc, 1, orpid, seqnum, 0);
+ qbman_eq_desc_set_response(eqdesc, (uint64_t)
+ DPAA2_VADDR_TO_IOVA(&dpio_dev->eqresp[
+ dpio_dev->eqresp_pi]), 1);
+ qbman_eq_desc_set_token(eqdesc, 1);
+
+ eqresp_meta = &dpio_dev->eqresp_meta[dpio_dev->eqresp_pi];
+ eqresp_meta->dpaa2_q = dpaa2_q;
+ eqresp_meta->mp = m->pool;
+
+ dpio_dev->eqresp_pi + 1 < MAX_EQ_RESP_ENTRIES ?
+ dpio_dev->eqresp_pi++ : (dpio_dev->eqresp_pi = 0);
+ } else {
+ qbman_eq_desc_set_orp(eqdesc, 0, orpid, seqnum, 0);
+ }
+ } else {
+ dq_idx = *dpaa2_seqn(m) - 1;
+ qbman_eq_desc_set_dca(eqdesc, 1, dq_idx, 0);
+ DPAA2_PER_LCORE_DQRR_SIZE--;
+ DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dq_idx);
+ }
+ *dpaa2_seqn(m) = DPAA2_INVALID_MBUF_SEQN;
+}
+
+
+static uint16_t
+dpaa2_sec_enqueue_burst_ordered(void *qp, struct rte_crypto_op **ops,
+ uint16_t nb_ops)
+{
+ /* Function to transmit the frames to given device and VQ*/
+ uint32_t loop;
+ int32_t ret;
+ struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
+ uint32_t frames_to_send, num_free_eq_desc, retry_count;
+ struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
+ struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
+ struct qbman_swp *swp;
+ uint16_t num_tx = 0;
+ uint16_t bpid;
+ struct rte_mempool *mb_pool;
+ struct dpaa2_sec_dev_private *priv =
+ dpaa2_qp->tx_vq.crypto_data->dev_private;
+
+ if (unlikely(nb_ops == 0))
+ return 0;
+
+ if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
+ DPAA2_SEC_ERR("sessionless crypto op not supported");
+ return 0;
+ }
+
+ if (!DPAA2_PER_LCORE_DPIO) {
+ ret = dpaa2_affine_qbman_swp();
+ if (ret) {
+ DPAA2_SEC_ERR("Failure in affining portal");
+ return 0;
+ }
+ }
+ swp = DPAA2_PER_LCORE_PORTAL;
+
+ while (nb_ops) {
+ frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
+ dpaa2_eqcr_size : nb_ops;
+
+ if (!priv->en_loose_ordered) {
+ if (*dpaa2_seqn((*ops)->sym->m_src)) {
+ num_free_eq_desc = dpaa2_free_eq_descriptors();
+ if (num_free_eq_desc < frames_to_send)
+ frames_to_send = num_free_eq_desc;
+ }
+ }
+
+ for (loop = 0; loop < frames_to_send; loop++) {
+ /*Prepare enqueue descriptor*/
+ qbman_eq_desc_clear(&eqdesc[loop]);
+ qbman_eq_desc_set_fq(&eqdesc[loop], dpaa2_qp->tx_vq.fqid);
+
+ if (*dpaa2_seqn((*ops)->sym->m_src))
+ dpaa2_sec_set_enqueue_descriptor(
+ &dpaa2_qp->tx_vq,
+ (*ops)->sym->m_src,
+ &eqdesc[loop]);
+ else
+ qbman_eq_desc_set_no_orp(&eqdesc[loop],
+ DPAA2_EQ_RESP_ERR_FQ);
+
+ /*Clear the unused FD fields before sending*/
+ memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
+ mb_pool = (*ops)->sym->m_src->pool;
+ bpid = mempool_to_bpid(mb_pool);
+ ret = build_sec_fd(*ops, &fd_arr[loop], bpid, dpaa2_qp);
+ if (ret) {
+ DPAA2_SEC_DP_DEBUG("FD build failed\n");
+ goto skip_tx;
+ }
+ ops++;
+ }
+
+ loop = 0;
+ retry_count = 0;
+ while (loop < frames_to_send) {
+ ret = qbman_swp_enqueue_multiple_desc(swp,
+ &eqdesc[loop], &fd_arr[loop],
+ frames_to_send - loop);
+ if (unlikely(ret < 0)) {
+ retry_count++;
+ if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
+ num_tx += loop;
+ nb_ops -= loop;
+ DPAA2_SEC_DP_DEBUG("Enqueue fail\n");
+ /* freeing the fle buffers */
+ while (loop < frames_to_send) {
+ free_fle(&fd_arr[loop],
+ dpaa2_qp);
+ loop++;
+ }
+ goto skip_tx;
+ }
+ } else {
+ loop += ret;
+ retry_count = 0;
+ }
+ }
+
+ num_tx += loop;
+ nb_ops -= loop;
+ }
+
+skip_tx:
+ dpaa2_qp->tx_vq.tx_pkts += num_tx;
+ dpaa2_qp->tx_vq.err_pkts += nb_ops;
+ return num_tx;
+}
+
+static uint16_t
dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
uint16_t nb_ops)
{
/* Function is responsible to receive frames for a given device and VQ*/
struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
- struct rte_cryptodev *dev =
- (struct rte_cryptodev *)(dpaa2_qp->rx_vq.dev);
struct qbman_result *dq_storage;
uint32_t fqid = dpaa2_qp->rx_vq.fqid;
int ret, num_rx = 0;
if (!DPAA2_PER_LCORE_DPIO) {
ret = dpaa2_affine_qbman_swp();
if (ret) {
- DPAA2_SEC_ERR("Failure in affining portal");
+ DPAA2_SEC_ERR(
+ "Failed to allocate IO portal, tid: %d\n",
+ rte_gettid());
return 0;
}
}
}
fd = qbman_result_DQ_fd(dq_storage);
- ops[num_rx] = sec_fd_to_mbuf(fd, dev->driver_id);
+ ops[num_rx] = sec_fd_to_mbuf(fd, dpaa2_qp);
if (unlikely(fd->simple.frc)) {
/* TODO Parse SEC errors */
- DPAA2_SEC_ERR("SEC returned Error - %x",
- fd->simple.frc);
+ if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_NO_DUMP) {
+ DPAA2_SEC_DP_ERR("SEC returned Error - %x\n",
+ fd->simple.frc);
+ if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_ERR_DUMP)
+ dpaa2_sec_dump(ops[num_rx]);
+ }
+
+ dpaa2_qp->rx_vq.err_pkts += 1;
ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
} else {
ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
dpaa2_qp->rx_vq.rx_pkts += num_rx;
- DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
+ DPAA2_SEC_DP_DEBUG("SEC RX pkts %d err pkts %" PRIu64 "\n", num_rx,
+ dpaa2_qp->rx_vq.err_pkts);
/*Return the total number of packets received to DPAA2 app*/
return num_rx;
}
dpaa2_free_dq_storage(qp->rx_vq.q_storage);
rte_free(qp->rx_vq.q_storage);
}
+ rte_mempool_free(qp->fle_pool);
rte_free(qp);
dev->data->queue_pairs[queue_pair_id] = NULL;
/** Setup a queue pair */
static int
dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
- __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
+ const struct rte_cryptodev_qp_conf *qp_conf,
__rte_unused int socket_id)
{
struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
struct dpseci_rx_queue_cfg cfg;
int32_t retcode;
+ char str[30];
PMD_INIT_FUNC_TRACE();
RTE_CACHE_LINE_SIZE);
if (!qp) {
DPAA2_SEC_ERR("malloc failed for rx/tx queues");
- return -1;
+ return -ENOMEM;
}
- qp->rx_vq.dev = dev;
- qp->tx_vq.dev = dev;
+ qp->rx_vq.crypto_data = dev->data;
+ qp->tx_vq.crypto_data = dev->data;
qp->rx_vq.q_storage = rte_malloc("sec dq storage",
sizeof(struct queue_storage_info_t),
RTE_CACHE_LINE_SIZE);
if (!qp->rx_vq.q_storage) {
DPAA2_SEC_ERR("malloc failed for q_storage");
- return -1;
+ return -ENOMEM;
}
memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
DPAA2_SEC_ERR("Unable to allocate dequeue storage");
- return -1;
+ return -ENOMEM;
}
dev->data->queue_pairs[qp_id] = qp;
+ snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d_%d",
+ getpid(), dev->data->dev_id, qp_id);
+ qp->fle_pool = rte_mempool_create((const char *)str,
+ qp_conf->nb_descriptors,
+ FLE_POOL_BUF_SIZE,
+ FLE_POOL_CACHE_SIZE, 0,
+ NULL, NULL, NULL, NULL,
+ SOCKET_ID_ANY, MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET);
+ if (!qp->fle_pool) {
+ DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
+ return -ENOMEM;
+ }
+
cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
cfg.user_ctx = (size_t)(&qp->rx_vq);
retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
return retcode;
}
-/** Return the number of allocated queue pairs */
-static uint32_t
-dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
-{
- PMD_INIT_FUNC_TRACE();
-
- return dev->data->nb_queue_pairs;
-}
-
/** Returns the size of the aesni gcm session structure */
static unsigned int
dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
}
static int
-dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
- struct rte_crypto_sym_xform *xform,
+dpaa2_sec_cipher_init(struct rte_crypto_sym_xform *xform,
dpaa2_sec_session *session)
{
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
struct alginfo cipherdata;
- int bufsize, i;
+ int bufsize, ret = 0;
struct ctxt_priv *priv;
struct sec_flow_context *flc;
RTE_CACHE_LINE_SIZE);
if (priv == NULL) {
DPAA2_SEC_ERR("No Memory for priv CTXT");
- return -1;
+ return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
-
flc = &priv->flc_desc[0].flc;
+ session->ctxt_type = DPAA2_SEC_CIPHER;
session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
RTE_CACHE_LINE_SIZE);
- if (session->cipher_key.data == NULL) {
+ if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
DPAA2_SEC_ERR("No Memory for cipher key");
rte_free(priv);
- return -1;
+ return -ENOMEM;
}
session->cipher_key.length = xform->cipher.key.length;
/* Set IV parameters */
session->iv.offset = xform->cipher.iv.offset;
session->iv.length = xform->cipher.iv.length;
+ session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
+ DIR_ENC : DIR_DEC;
switch (xform->cipher.algo) {
case RTE_CRYPTO_CIPHER_AES_CBC:
cipherdata.algtype = OP_ALG_ALGSEL_AES;
cipherdata.algmode = OP_ALG_AAI_CBC;
session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
+ bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
+ SHR_NEVER, &cipherdata,
+ session->iv.length,
+ session->dir);
break;
case RTE_CRYPTO_CIPHER_3DES_CBC:
cipherdata.algtype = OP_ALG_ALGSEL_3DES;
cipherdata.algmode = OP_ALG_AAI_CBC;
session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
+ bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
+ SHR_NEVER, &cipherdata,
+ session->iv.length,
+ session->dir);
+ break;
+ case RTE_CRYPTO_CIPHER_DES_CBC:
+ cipherdata.algtype = OP_ALG_ALGSEL_DES;
+ cipherdata.algmode = OP_ALG_AAI_CBC;
+ session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
+ bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
+ SHR_NEVER, &cipherdata,
+ session->iv.length,
+ session->dir);
break;
case RTE_CRYPTO_CIPHER_AES_CTR:
cipherdata.algtype = OP_ALG_ALGSEL_AES;
cipherdata.algmode = OP_ALG_AAI_CTR;
session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
+ bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
+ SHR_NEVER, &cipherdata,
+ session->iv.length,
+ session->dir);
break;
- case RTE_CRYPTO_CIPHER_3DES_CTR:
+ case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+ cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
+ session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
+ bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
+ &cipherdata,
+ session->dir);
+ break;
+ case RTE_CRYPTO_CIPHER_ZUC_EEA3:
+ cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
+ session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
+ bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
+ &cipherdata,
+ session->dir);
+ break;
+ case RTE_CRYPTO_CIPHER_KASUMI_F8:
+ case RTE_CRYPTO_CIPHER_AES_F8:
case RTE_CRYPTO_CIPHER_AES_ECB:
case RTE_CRYPTO_CIPHER_3DES_ECB:
+ case RTE_CRYPTO_CIPHER_3DES_CTR:
case RTE_CRYPTO_CIPHER_AES_XTS:
- case RTE_CRYPTO_CIPHER_AES_F8:
case RTE_CRYPTO_CIPHER_ARC4:
- case RTE_CRYPTO_CIPHER_KASUMI_F8:
- case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
- case RTE_CRYPTO_CIPHER_ZUC_EEA3:
case RTE_CRYPTO_CIPHER_NULL:
DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
xform->cipher.algo);
+ ret = -ENOTSUP;
goto error_out;
default:
DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
xform->cipher.algo);
+ ret = -ENOTSUP;
goto error_out;
}
- session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
- DIR_ENC : DIR_DEC;
- bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
- &cipherdata, NULL, session->iv.length,
- session->dir);
if (bufsize < 0) {
DPAA2_SEC_ERR("Crypto: Descriptor build failed");
+ ret = -EINVAL;
goto error_out;
}
- flc->dhr = 0;
- flc->bpv0 = 0x1;
- flc->mode_bits = 0x8000;
flc->word1_sdl = (uint8_t)bufsize;
- flc->word2_rflc_31_0 = lower_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
- flc->word3_rflc_63_32 = upper_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
session->ctxt = priv;
+#ifdef CAAM_DESC_DEBUG
+ int i;
for (i = 0; i < bufsize; i++)
DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
-
- return 0;
+#endif
+ return ret;
error_out:
rte_free(session->cipher_key.data);
rte_free(priv);
- return -1;
+ return ret;
}
static int
-dpaa2_sec_auth_init(struct rte_cryptodev *dev,
- struct rte_crypto_sym_xform *xform,
+dpaa2_sec_auth_init(struct rte_crypto_sym_xform *xform,
dpaa2_sec_session *session)
{
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
struct alginfo authdata;
- int bufsize, i;
+ int bufsize, ret = 0;
struct ctxt_priv *priv;
struct sec_flow_context *flc;
RTE_CACHE_LINE_SIZE);
if (priv == NULL) {
DPAA2_SEC_ERR("No Memory for priv CTXT");
- return -1;
+ return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
flc = &priv->flc_desc[DESC_INITFINAL].flc;
- session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
+ session->ctxt_type = DPAA2_SEC_AUTH;
+ session->auth_key.length = xform->auth.key.length;
+ if (xform->auth.key.length) {
+ session->auth_key.data = rte_zmalloc(NULL,
+ xform->auth.key.length,
RTE_CACHE_LINE_SIZE);
- if (session->auth_key.data == NULL) {
- DPAA2_SEC_ERR("Unable to allocate memory for auth key");
- rte_free(priv);
- return -1;
+ if (session->auth_key.data == NULL) {
+ DPAA2_SEC_ERR("Unable to allocate memory for auth key");
+ rte_free(priv);
+ return -ENOMEM;
+ }
+ memcpy(session->auth_key.data, xform->auth.key.data,
+ xform->auth.key.length);
+ authdata.key = (size_t)session->auth_key.data;
+ authdata.key_enc_flags = 0;
+ authdata.key_type = RTA_DATA_IMM;
}
- session->auth_key.length = xform->auth.key.length;
-
- memcpy(session->auth_key.data, xform->auth.key.data,
- xform->auth.key.length);
- authdata.key = (size_t)session->auth_key.data;
authdata.keylen = session->auth_key.length;
- authdata.key_enc_flags = 0;
- authdata.key_type = RTA_DATA_IMM;
session->digest_length = xform->auth.digest_length;
+ session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
+ DIR_ENC : DIR_DEC;
switch (xform->auth.algo) {
case RTE_CRYPTO_AUTH_SHA1_HMAC:
authdata.algtype = OP_ALG_ALGSEL_SHA1;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
case RTE_CRYPTO_AUTH_MD5_HMAC:
authdata.algtype = OP_ALG_ALGSEL_MD5;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
case RTE_CRYPTO_AUTH_SHA256_HMAC:
authdata.algtype = OP_ALG_ALGSEL_SHA256;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
case RTE_CRYPTO_AUTH_SHA384_HMAC:
authdata.algtype = OP_ALG_ALGSEL_SHA384;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
case RTE_CRYPTO_AUTH_SHA512_HMAC:
authdata.algtype = OP_ALG_ALGSEL_SHA512;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
case RTE_CRYPTO_AUTH_SHA224_HMAC:
authdata.algtype = OP_ALG_ALGSEL_SHA224;
authdata.algmode = OP_ALG_AAI_HMAC;
session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
+ bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
break;
- case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
- case RTE_CRYPTO_AUTH_NULL:
+ authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
+ authdata.algmode = OP_ALG_AAI_F9;
+ session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
+ session->iv.offset = xform->auth.iv.offset;
+ session->iv.length = xform->auth.iv.length;
+ bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
+ case RTE_CRYPTO_AUTH_ZUC_EIA3:
+ authdata.algtype = OP_ALG_ALGSEL_ZUCA;
+ authdata.algmode = OP_ALG_AAI_F9;
+ session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
+ session->iv.offset = xform->auth.iv.offset;
+ session->iv.length = xform->auth.iv.length;
+ bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_SHA1:
+ authdata.algtype = OP_ALG_ALGSEL_SHA1;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_SHA1;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
+ case RTE_CRYPTO_AUTH_MD5:
+ authdata.algtype = OP_ALG_ALGSEL_MD5;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_MD5;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_SHA256:
+ authdata.algtype = OP_ALG_ALGSEL_SHA256;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_SHA256;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
+ case RTE_CRYPTO_AUTH_SHA384:
+ authdata.algtype = OP_ALG_ALGSEL_SHA384;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_SHA384;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_SHA512:
+ authdata.algtype = OP_ALG_ALGSEL_SHA512;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_SHA512;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_SHA224:
- case RTE_CRYPTO_AUTH_SHA384:
- case RTE_CRYPTO_AUTH_MD5:
- case RTE_CRYPTO_AUTH_AES_GMAC:
- case RTE_CRYPTO_AUTH_KASUMI_F9:
+ authdata.algtype = OP_ALG_ALGSEL_SHA224;
+ authdata.algmode = OP_ALG_AAI_HASH;
+ session->auth_alg = RTE_CRYPTO_AUTH_SHA224;
+ bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
+ case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
+ authdata.algtype = OP_ALG_ALGSEL_AES;
+ authdata.algmode = OP_ALG_AAI_XCBC_MAC;
+ session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
+ bufsize = cnstr_shdsc_aes_mac(
+ priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_AES_CMAC:
+ authdata.algtype = OP_ALG_ALGSEL_AES;
+ authdata.algmode = OP_ALG_AAI_CMAC;
+ session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
+ bufsize = cnstr_shdsc_aes_mac(
+ priv->flc_desc[DESC_INITFINAL].desc,
+ 1, 0, SHR_NEVER, &authdata,
+ !session->dir,
+ session->digest_length);
+ break;
case RTE_CRYPTO_AUTH_AES_CBC_MAC:
- case RTE_CRYPTO_AUTH_ZUC_EIA3:
+ case RTE_CRYPTO_AUTH_AES_GMAC:
+ case RTE_CRYPTO_AUTH_KASUMI_F9:
+ case RTE_CRYPTO_AUTH_NULL:
DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
xform->auth.algo);
+ ret = -ENOTSUP;
goto error_out;
default:
DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
xform->auth.algo);
+ ret = -ENOTSUP;
goto error_out;
}
- session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
- DIR_ENC : DIR_DEC;
- bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
- 1, 0, &authdata, !session->dir,
- session->digest_length);
if (bufsize < 0) {
DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+ ret = -EINVAL;
goto error_out;
}
flc->word1_sdl = (uint8_t)bufsize;
- flc->word2_rflc_31_0 = lower_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
- flc->word3_rflc_63_32 = upper_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
session->ctxt = priv;
+#ifdef CAAM_DESC_DEBUG
+ int i;
for (i = 0; i < bufsize; i++)
DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
i, priv->flc_desc[DESC_INITFINAL].desc[i]);
+#endif
-
- return 0;
+ return ret;
error_out:
rte_free(session->auth_key.data);
rte_free(priv);
- return -1;
+ return ret;
}
static int
-dpaa2_sec_aead_init(struct rte_cryptodev *dev,
- struct rte_crypto_sym_xform *xform,
+dpaa2_sec_aead_init(struct rte_crypto_sym_xform *xform,
dpaa2_sec_session *session)
{
struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
struct alginfo aeaddata;
- int bufsize, i;
+ int bufsize;
struct ctxt_priv *priv;
struct sec_flow_context *flc;
struct rte_crypto_aead_xform *aead_xform = &xform->aead;
- int err;
+ int err, ret = 0;
PMD_INIT_FUNC_TRACE();
RTE_CACHE_LINE_SIZE);
if (priv == NULL) {
DPAA2_SEC_ERR("No Memory for priv CTXT");
- return -1;
+ return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
flc = &priv->flc_desc[0].flc;
session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
DPAA2_SEC_ERR("No Memory for aead key");
rte_free(priv);
- return -1;
+ return -ENOMEM;
}
memcpy(session->aead_key.data, aead_xform->key.data,
aead_xform->key.length);
case RTE_CRYPTO_AEAD_AES_CCM:
DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
aead_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
default:
DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
aead_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
}
session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
priv->flc_desc[0].desc[0] = aeaddata.keylen;
err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
- MIN_JOB_DESC_SIZE,
+ DESC_JOB_IO_LEN,
(unsigned int *)priv->flc_desc[0].desc,
&priv->flc_desc[0].desc[1], 1);
if (err < 0) {
DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+ ret = -EINVAL;
goto error_out;
}
if (priv->flc_desc[0].desc[1] & 1) {
if (session->dir == DIR_ENC)
bufsize = cnstr_shdsc_gcm_encap(
- priv->flc_desc[0].desc, 1, 0,
+ priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
&aeaddata, session->iv.length,
session->digest_length);
else
bufsize = cnstr_shdsc_gcm_decap(
- priv->flc_desc[0].desc, 1, 0,
+ priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
&aeaddata, session->iv.length,
session->digest_length);
if (bufsize < 0) {
DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+ ret = -EINVAL;
goto error_out;
}
flc->word1_sdl = (uint8_t)bufsize;
- flc->word2_rflc_31_0 = lower_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
- flc->word3_rflc_63_32 = upper_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
session->ctxt = priv;
+#ifdef CAAM_DESC_DEBUG
+ int i;
for (i = 0; i < bufsize; i++)
DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
i, priv->flc_desc[0].desc[i]);
-
- return 0;
+#endif
+ return ret;
error_out:
rte_free(session->aead_key.data);
rte_free(priv);
- return -1;
+ return ret;
}
static int
-dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
- struct rte_crypto_sym_xform *xform,
+dpaa2_sec_aead_chain_init(struct rte_crypto_sym_xform *xform,
dpaa2_sec_session *session)
{
- struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
struct alginfo authdata, cipherdata;
- int bufsize, i;
+ int bufsize;
struct ctxt_priv *priv;
struct sec_flow_context *flc;
struct rte_crypto_cipher_xform *cipher_xform;
struct rte_crypto_auth_xform *auth_xform;
- int err;
+ int err, ret = 0;
PMD_INIT_FUNC_TRACE();
RTE_CACHE_LINE_SIZE);
if (priv == NULL) {
DPAA2_SEC_ERR("No Memory for priv CTXT");
- return -1;
+ return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
flc = &priv->flc_desc[0].flc;
session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
DPAA2_SEC_ERR("No Memory for cipher key");
rte_free(priv);
- return -1;
+ return -ENOMEM;
}
session->cipher_key.length = cipher_xform->key.length;
session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
DPAA2_SEC_ERR("No Memory for auth key");
rte_free(session->cipher_key.data);
rte_free(priv);
- return -1;
+ return -ENOMEM;
}
session->auth_key.length = auth_xform->key.length;
memcpy(session->cipher_key.data, cipher_xform->key.data,
session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
break;
case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
+ authdata.algtype = OP_ALG_ALGSEL_AES;
+ authdata.algmode = OP_ALG_AAI_XCBC_MAC;
+ session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
+ break;
+ case RTE_CRYPTO_AUTH_AES_CMAC:
+ authdata.algtype = OP_ALG_ALGSEL_AES;
+ authdata.algmode = OP_ALG_AAI_CMAC;
+ session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
+ break;
+ case RTE_CRYPTO_AUTH_AES_CBC_MAC:
+ case RTE_CRYPTO_AUTH_AES_GMAC:
case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
case RTE_CRYPTO_AUTH_NULL:
case RTE_CRYPTO_AUTH_SHA1:
case RTE_CRYPTO_AUTH_SHA224:
case RTE_CRYPTO_AUTH_SHA384:
case RTE_CRYPTO_AUTH_MD5:
- case RTE_CRYPTO_AUTH_AES_GMAC:
case RTE_CRYPTO_AUTH_KASUMI_F9:
- case RTE_CRYPTO_AUTH_AES_CMAC:
- case RTE_CRYPTO_AUTH_AES_CBC_MAC:
case RTE_CRYPTO_AUTH_ZUC_EIA3:
DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
auth_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
default:
DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
auth_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
}
cipherdata.key = (size_t)session->cipher_key.data;
cipherdata.algmode = OP_ALG_AAI_CBC;
session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
break;
+ case RTE_CRYPTO_CIPHER_DES_CBC:
+ cipherdata.algtype = OP_ALG_ALGSEL_DES;
+ cipherdata.algmode = OP_ALG_AAI_CBC;
+ session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
+ break;
case RTE_CRYPTO_CIPHER_AES_CTR:
cipherdata.algtype = OP_ALG_ALGSEL_AES;
cipherdata.algmode = OP_ALG_AAI_CTR;
session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
break;
case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+ case RTE_CRYPTO_CIPHER_ZUC_EEA3:
case RTE_CRYPTO_CIPHER_NULL:
case RTE_CRYPTO_CIPHER_3DES_ECB:
+ case RTE_CRYPTO_CIPHER_3DES_CTR:
case RTE_CRYPTO_CIPHER_AES_ECB:
case RTE_CRYPTO_CIPHER_KASUMI_F8:
DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
cipher_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
default:
DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
cipher_xform->algo);
+ ret = -ENOTSUP;
goto error_out;
}
session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
priv->flc_desc[0].desc[0] = cipherdata.keylen;
priv->flc_desc[0].desc[1] = authdata.keylen;
err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
- MIN_JOB_DESC_SIZE,
+ DESC_JOB_IO_LEN,
(unsigned int *)priv->flc_desc[0].desc,
&priv->flc_desc[0].desc[2], 2);
if (err < 0) {
DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+ ret = -EINVAL;
goto error_out;
}
if (priv->flc_desc[0].desc[2] & 1) {
if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
- 0, &cipherdata, &authdata,
+ 0, SHR_SERIAL,
+ &cipherdata, &authdata,
session->iv.length,
- ctxt->auth_only_len,
session->digest_length,
session->dir);
if (bufsize < 0) {
DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+ ret = -EINVAL;
goto error_out;
}
} else {
DPAA2_SEC_ERR("Hash before cipher not supported");
+ ret = -ENOTSUP;
goto error_out;
}
flc->word1_sdl = (uint8_t)bufsize;
- flc->word2_rflc_31_0 = lower_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
- flc->word3_rflc_63_32 = upper_32_bits(
- (size_t)&(((struct dpaa2_sec_qp *)
- dev->data->queue_pairs[0])->rx_vq));
session->ctxt = priv;
+#ifdef CAAM_DESC_DEBUG
+ int i;
for (i = 0; i < bufsize; i++)
DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
i, priv->flc_desc[0].desc[i]);
+#endif
- return 0;
+ return ret;
error_out:
rte_free(session->cipher_key.data);
rte_free(session->auth_key.data);
rte_free(priv);
- return -1;
+ return ret;
}
static int
-dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
- struct rte_crypto_sym_xform *xform, void *sess)
+dpaa2_sec_set_session_parameters(struct rte_crypto_sym_xform *xform, void *sess)
{
dpaa2_sec_session *session = sess;
+ int ret;
PMD_INIT_FUNC_TRACE();
if (unlikely(sess == NULL)) {
DPAA2_SEC_ERR("Invalid session struct");
- return -1;
+ return -EINVAL;
}
memset(session, 0, sizeof(dpaa2_sec_session));
/* Cipher Only */
if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
- session->ctxt_type = DPAA2_SEC_CIPHER;
- dpaa2_sec_cipher_init(dev, xform, session);
+ ret = dpaa2_sec_cipher_init(xform, session);
/* Authentication Only */
} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
xform->next == NULL) {
- session->ctxt_type = DPAA2_SEC_AUTH;
- dpaa2_sec_auth_init(dev, xform, session);
+ ret = dpaa2_sec_auth_init(xform, session);
/* Cipher then Authenticate */
} else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
session->ext_params.aead_ctxt.auth_cipher_text = true;
- dpaa2_sec_aead_chain_init(dev, xform, session);
-
+ if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
+ ret = dpaa2_sec_auth_init(xform, session);
+ else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
+ ret = dpaa2_sec_cipher_init(xform, session);
+ else
+ ret = dpaa2_sec_aead_chain_init(xform, session);
/* Authenticate then Cipher */
} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
session->ext_params.aead_ctxt.auth_cipher_text = false;
- dpaa2_sec_aead_chain_init(dev, xform, session);
-
+ if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
+ ret = dpaa2_sec_cipher_init(xform, session);
+ else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
+ ret = dpaa2_sec_auth_init(xform, session);
+ else
+ ret = dpaa2_sec_aead_chain_init(xform, session);
/* AEAD operation for AES-GCM kind of Algorithms */
} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
xform->next == NULL) {
- dpaa2_sec_aead_init(dev, xform, session);
+ ret = dpaa2_sec_aead_init(xform, session);
} else {
DPAA2_SEC_ERR("Invalid crypto type");
return -EINVAL;
}
- return 0;
+ return ret;
}
+#ifdef RTE_LIB_SECURITY
static int
dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
dpaa2_sec_session *session,
RTE_CACHE_LINE_SIZE);
if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
DPAA2_SEC_ERR("No Memory for aead key");
- return -1;
+ return -ENOMEM;
}
memcpy(session->aead_key.data, aead_xform->key.data,
aead_xform->key.length);
switch (aead_xform->algo) {
case RTE_CRYPTO_AEAD_AES_GCM:
- aeaddata->algtype = OP_ALG_ALGSEL_AES;
+ switch (session->digest_length) {
+ case 8:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
+ break;
+ case 12:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
+ break;
+ case 16:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
+ break;
+ default:
+ DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
+ session->digest_length);
+ return -EINVAL;
+ }
aeaddata->algmode = OP_ALG_AAI_GCM;
session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
break;
case RTE_CRYPTO_AEAD_AES_CCM:
- aeaddata->algtype = OP_ALG_ALGSEL_AES;
+ switch (session->digest_length) {
+ case 8:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
+ break;
+ case 12:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
+ break;
+ case 16:
+ aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
+ break;
+ default:
+ DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
+ session->digest_length);
+ return -EINVAL;
+ }
aeaddata->algmode = OP_ALG_AAI_CCM;
session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
break;
default:
DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
aead_xform->algo);
- return -1;
+ return -ENOTSUP;
}
session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
DIR_ENC : DIR_DEC;
memcpy(session->auth_key.data, auth_xform->key.data,
auth_xform->key.length);
session->auth_alg = auth_xform->algo;
+ session->digest_length = auth_xform->digest_length;
} else {
session->auth_key.data = NULL;
session->auth_key.length = 0;
case RTE_CRYPTO_AUTH_SHA256_HMAC:
authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
authdata->algmode = OP_ALG_AAI_HMAC;
+ if (session->digest_length != 16)
+ DPAA2_SEC_WARN(
+ "+++Using sha256-hmac truncated len is non-standard,"
+ "it will not work with lookaside proto");
break;
case RTE_CRYPTO_AUTH_SHA384_HMAC:
authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
authdata->algmode = OP_ALG_AAI_HMAC;
break;
+ case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
+ authdata->algtype = OP_PCL_IPSEC_AES_XCBC_MAC_96;
+ authdata->algmode = OP_ALG_AAI_XCBC_MAC;
+ break;
case RTE_CRYPTO_AUTH_AES_CMAC:
authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
+ authdata->algmode = OP_ALG_AAI_CMAC;
break;
case RTE_CRYPTO_AUTH_NULL:
authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
break;
case RTE_CRYPTO_AUTH_SHA224_HMAC:
- case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
case RTE_CRYPTO_AUTH_SHA1:
case RTE_CRYPTO_AUTH_SHA256:
case RTE_CRYPTO_AUTH_ZUC_EIA3:
DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
session->auth_alg);
- return -1;
+ return -ENOTSUP;
default:
DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
session->auth_alg);
- return -1;
+ return -ENOTSUP;
}
cipherdata->key = (size_t)session->cipher_key.data;
cipherdata->keylen = session->cipher_key.length;
cipherdata->algtype = OP_PCL_IPSEC_3DES;
cipherdata->algmode = OP_ALG_AAI_CBC;
break;
+ case RTE_CRYPTO_CIPHER_DES_CBC:
+ cipherdata->algtype = OP_PCL_IPSEC_DES;
+ cipherdata->algmode = OP_ALG_AAI_CBC;
+ break;
case RTE_CRYPTO_CIPHER_AES_CTR:
cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
cipherdata->algmode = OP_ALG_AAI_CTR;
cipherdata->algtype = OP_PCL_IPSEC_NULL;
break;
case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+ case RTE_CRYPTO_CIPHER_ZUC_EEA3:
case RTE_CRYPTO_CIPHER_3DES_ECB:
+ case RTE_CRYPTO_CIPHER_3DES_CTR:
case RTE_CRYPTO_CIPHER_AES_ECB:
case RTE_CRYPTO_CIPHER_KASUMI_F8:
DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
session->cipher_alg);
- return -1;
+ return -ENOTSUP;
default:
DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
session->cipher_alg);
- return -1;
+ return -ENOTSUP;
}
return 0;
}
-#ifdef RTE_LIBRTE_SECURITY_TEST
-static uint8_t aes_cbc_iv[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
-#endif
-
static int
dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
struct rte_security_session_conf *conf,
struct rte_crypto_aead_xform *aead_xform = NULL;
dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
struct ctxt_priv *priv;
- struct ipsec_encap_pdb encap_pdb;
- struct ipsec_decap_pdb decap_pdb;
struct alginfo authdata, cipherdata;
int bufsize;
struct sec_flow_context *flc;
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
int ret = -1;
PMD_INIT_FUNC_TRACE();
return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
flc = &priv->flc_desc[0].flc;
+ if (ipsec_xform->life.bytes_hard_limit != 0 ||
+ ipsec_xform->life.bytes_soft_limit != 0 ||
+ ipsec_xform->life.packets_hard_limit != 0 ||
+ ipsec_xform->life.packets_soft_limit != 0)
+ return -ENOTSUP;
+
memset(session, 0, sizeof(dpaa2_sec_session));
if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
aead_xform = &conf->crypto_xform->aead;
ret = dpaa2_sec_ipsec_aead_init(aead_xform,
session, &cipherdata);
+ authdata.keylen = 0;
+ authdata.algtype = 0;
} else {
DPAA2_SEC_ERR("XFORM not specified");
ret = -EINVAL;
session->ctxt_type = DPAA2_SEC_IPSEC;
if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+ uint8_t *hdr = NULL;
struct ip ip4_hdr;
+ struct rte_ipv6_hdr ip6_hdr;
+ struct ipsec_encap_pdb encap_pdb;
flc->dhr = SEC_FLC_DHR_OUTBOUND;
- ip4_hdr.ip_v = IPVERSION;
- ip4_hdr.ip_hl = 5;
- ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
- ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
- ip4_hdr.ip_id = 0;
- ip4_hdr.ip_off = 0;
- ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
- ip4_hdr.ip_p = IPPROTO_ESP;
- ip4_hdr.ip_sum = 0;
- ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
- ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
- ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)&ip4_hdr,
- sizeof(struct ip));
-
/* For Sec Proto only one descriptor is required. */
memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
+
+ /* copy algo specific data to PDB */
+ switch (cipherdata.algtype) {
+ case OP_PCL_IPSEC_AES_CTR:
+ encap_pdb.ctr.ctr_initial = 0x00000001;
+ encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
+ break;
+ case OP_PCL_IPSEC_AES_GCM8:
+ case OP_PCL_IPSEC_AES_GCM12:
+ case OP_PCL_IPSEC_AES_GCM16:
+ memcpy(encap_pdb.gcm.salt,
+ (uint8_t *)&(ipsec_xform->salt), 4);
+ break;
+ }
+
encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
PDBOPTS_ESP_OIHI_PDB_INL |
PDBOPTS_ESP_IVSRC |
- PDBHMO_ESP_ENCAP_DTTL |
PDBHMO_ESP_SNR;
+ if (ipsec_xform->options.dec_ttl)
+ encap_pdb.options |= PDBHMO_ESP_ENCAP_DTTL;
+ if (ipsec_xform->options.esn)
+ encap_pdb.options |= PDBOPTS_ESP_ESN;
encap_pdb.spi = ipsec_xform->spi;
- encap_pdb.ip_hdr_len = sizeof(struct ip);
-
session->dir = DIR_ENC;
+ if (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
+ encap_pdb.ip_hdr_len = sizeof(struct ip);
+ ip4_hdr.ip_v = IPVERSION;
+ ip4_hdr.ip_hl = 5;
+ ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
+ ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
+ ip4_hdr.ip_id = 0;
+ ip4_hdr.ip_off = 0;
+ ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
+ ip4_hdr.ip_p = IPPROTO_ESP;
+ ip4_hdr.ip_sum = 0;
+ ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
+ ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
+ ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
+ &ip4_hdr, sizeof(struct ip));
+ hdr = (uint8_t *)&ip4_hdr;
+ } else if (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
+ ip6_hdr.vtc_flow = rte_cpu_to_be_32(
+ DPAA2_IPv6_DEFAULT_VTC_FLOW |
+ ((ipsec_xform->tunnel.ipv6.dscp <<
+ RTE_IPV6_HDR_TC_SHIFT) &
+ RTE_IPV6_HDR_TC_MASK) |
+ ((ipsec_xform->tunnel.ipv6.flabel <<
+ RTE_IPV6_HDR_FL_SHIFT) &
+ RTE_IPV6_HDR_FL_MASK));
+ /* Payload length will be updated by HW */
+ ip6_hdr.payload_len = 0;
+ ip6_hdr.hop_limits =
+ ipsec_xform->tunnel.ipv6.hlimit;
+ ip6_hdr.proto = (ipsec_xform->proto ==
+ RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
+ IPPROTO_ESP : IPPROTO_AH;
+ memcpy(&ip6_hdr.src_addr,
+ &ipsec_xform->tunnel.ipv6.src_addr, 16);
+ memcpy(&ip6_hdr.dst_addr,
+ &ipsec_xform->tunnel.ipv6.dst_addr, 16);
+ encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
+ hdr = (uint8_t *)&ip6_hdr;
+ }
+
bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
- 1, 0, SHR_SERIAL, &encap_pdb,
- (uint8_t *)&ip4_hdr,
- &cipherdata, &authdata);
+ 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
+ SHR_WAIT : SHR_SERIAL, &encap_pdb,
+ hdr, &cipherdata, &authdata);
} else if (ipsec_xform->direction ==
RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
+ struct ipsec_decap_pdb decap_pdb;
+
flc->dhr = SEC_FLC_DHR_INBOUND;
memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
- decap_pdb.options = sizeof(struct ip) << 16;
+ /* copy algo specific data to PDB */
+ switch (cipherdata.algtype) {
+ case OP_PCL_IPSEC_AES_CTR:
+ decap_pdb.ctr.ctr_initial = 0x00000001;
+ decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
+ break;
+ case OP_PCL_IPSEC_AES_GCM8:
+ case OP_PCL_IPSEC_AES_GCM12:
+ case OP_PCL_IPSEC_AES_GCM16:
+ memcpy(decap_pdb.gcm.salt,
+ (uint8_t *)&(ipsec_xform->salt), 4);
+ break;
+ }
+
+ decap_pdb.options = (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
+ sizeof(struct ip) << 16 :
+ sizeof(struct rte_ipv6_hdr) << 16;
+ if (ipsec_xform->options.esn)
+ decap_pdb.options |= PDBOPTS_ESP_ESN;
+
+ if (ipsec_xform->replay_win_sz) {
+ uint32_t win_sz;
+ win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
+
+ if (rta_sec_era < RTA_SEC_ERA_10 && win_sz > 128) {
+ DPAA2_SEC_INFO("Max Anti replay Win sz = 128");
+ win_sz = 128;
+ }
+ switch (win_sz) {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16:
+ case 32:
+ decap_pdb.options |= PDBOPTS_ESP_ARS32;
+ break;
+ case 64:
+ decap_pdb.options |= PDBOPTS_ESP_ARS64;
+ break;
+ case 256:
+ decap_pdb.options |= PDBOPTS_ESP_ARS256;
+ break;
+ case 512:
+ decap_pdb.options |= PDBOPTS_ESP_ARS512;
+ break;
+ case 1024:
+ decap_pdb.options |= PDBOPTS_ESP_ARS1024;
+ break;
+ case 128:
+ default:
+ decap_pdb.options |= PDBOPTS_ESP_ARS128;
+ }
+ }
session->dir = DIR_DEC;
bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
- 1, 0, SHR_SERIAL,
+ 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
+ SHR_WAIT : SHR_SERIAL,
&decap_pdb, &cipherdata, &authdata);
} else
goto out;
struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
struct rte_crypto_sym_xform *xform = conf->crypto_xform;
struct rte_crypto_auth_xform *auth_xform = NULL;
- struct rte_crypto_cipher_xform *cipher_xform;
+ struct rte_crypto_cipher_xform *cipher_xform = NULL;
dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
struct ctxt_priv *priv;
- struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
struct alginfo authdata, cipherdata;
+ struct alginfo *p_authdata = NULL;
int bufsize = -1;
struct sec_flow_context *flc;
#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
return -ENOMEM;
}
- priv->fle_pool = dev_priv->fle_pool;
flc = &priv->flc_desc[0].flc;
/* find xfrm types */
- if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
- cipher_xform = &xform->cipher;
- } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
- xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
- session->ext_params.aead_ctxt.auth_cipher_text = true;
+ if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
cipher_xform = &xform->cipher;
- auth_xform = &xform->next->auth;
- } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
- xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
- session->ext_params.aead_ctxt.auth_cipher_text = false;
- cipher_xform = &xform->next->cipher;
+ if (xform->next != NULL &&
+ xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
+ session->ext_params.aead_ctxt.auth_cipher_text = true;
+ auth_xform = &xform->next->auth;
+ }
+ } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
auth_xform = &xform->auth;
+ if (xform->next != NULL &&
+ xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
+ session->ext_params.aead_ctxt.auth_cipher_text = false;
+ cipher_xform = &xform->next->cipher;
+ }
} else {
DPAA2_SEC_ERR("Invalid crypto type");
return -EINVAL;
session->pdcp.bearer = pdcp_xform->bearer;
session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
session->pdcp.sn_size = pdcp_xform->sn_size;
-#ifdef ENABLE_HFN_OVERRIDE
- session->pdcp.hfn_ovd = pdcp_xform->hfn_ovd;
-#endif
session->pdcp.hfn = pdcp_xform->hfn;
session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
+ session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
+ /* hfv ovd offset location is stored in iv.offset value*/
+ if (cipher_xform)
+ session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
cipherdata.key = (size_t)session->cipher_key.data;
cipherdata.keylen = session->cipher_key.length;
goto out;
}
- /* Auth is only applicable for control mode operation. */
- if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
- if (pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_5) {
- DPAA2_SEC_ERR(
- "PDCP Seq Num size should be 5 bits for cmode");
- goto out;
- }
- if (auth_xform) {
- session->auth_key.data = rte_zmalloc(NULL,
- auth_xform->key.length,
- RTE_CACHE_LINE_SIZE);
- if (session->auth_key.data == NULL &&
- auth_xform->key.length > 0) {
- DPAA2_SEC_ERR("No Memory for auth key");
- rte_free(session->cipher_key.data);
- rte_free(priv);
- return -ENOMEM;
- }
- session->auth_key.length = auth_xform->key.length;
- memcpy(session->auth_key.data, auth_xform->key.data,
- auth_xform->key.length);
- session->auth_alg = auth_xform->algo;
- } else {
- session->auth_key.data = NULL;
- session->auth_key.length = 0;
- session->auth_alg = RTE_CRYPTO_AUTH_NULL;
+ if (auth_xform) {
+ session->auth_key.data = rte_zmalloc(NULL,
+ auth_xform->key.length,
+ RTE_CACHE_LINE_SIZE);
+ if (!session->auth_key.data &&
+ auth_xform->key.length > 0) {
+ DPAA2_SEC_ERR("No Memory for auth key");
+ rte_free(session->cipher_key.data);
+ rte_free(priv);
+ return -ENOMEM;
}
- authdata.key = (size_t)session->auth_key.data;
- authdata.keylen = session->auth_key.length;
- authdata.key_enc_flags = 0;
- authdata.key_type = RTA_DATA_IMM;
+ session->auth_key.length = auth_xform->key.length;
+ memcpy(session->auth_key.data, auth_xform->key.data,
+ auth_xform->key.length);
+ session->auth_alg = auth_xform->algo;
+ } else {
+ session->auth_key.data = NULL;
+ session->auth_key.length = 0;
+ session->auth_alg = 0;
+ }
+ authdata.key = (size_t)session->auth_key.data;
+ authdata.keylen = session->auth_key.length;
+ authdata.key_enc_flags = 0;
+ authdata.key_type = RTA_DATA_IMM;
+ if (session->auth_alg) {
switch (session->auth_alg) {
case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
authdata.algtype = PDCP_AUTH_TYPE_SNOW;
goto out;
}
+ p_authdata = &authdata;
+ } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
+ DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
+ goto out;
+ }
+
+ if (pdcp_xform->sdap_enabled) {
+ int nb_keys_to_inline =
+ rta_inline_pdcp_sdap_query(authdata.algtype,
+ cipherdata.algtype,
+ session->pdcp.sn_size,
+ session->pdcp.hfn_ovd);
+ if (nb_keys_to_inline >= 1) {
+ cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
+ cipherdata.key_type = RTA_DATA_PTR;
+ }
+ if (nb_keys_to_inline >= 2) {
+ authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
+ authdata.key_type = RTA_DATA_PTR;
+ }
+ } else {
+ if (rta_inline_pdcp_query(authdata.algtype,
+ cipherdata.algtype,
+ session->pdcp.sn_size,
+ session->pdcp.hfn_ovd)) {
+ cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
+ cipherdata.key_type = RTA_DATA_PTR;
+ }
+ }
+
+ if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
if (session->dir == DIR_ENC)
bufsize = cnstr_shdsc_pdcp_c_plane_encap(
priv->flc_desc[0].desc, 1, swap,
pdcp_xform->hfn,
+ session->pdcp.sn_size,
pdcp_xform->bearer,
pdcp_xform->pkt_dir,
pdcp_xform->hfn_threshold,
- &cipherdata, &authdata,
- 0);
+ &cipherdata, &authdata);
else if (session->dir == DIR_DEC)
bufsize = cnstr_shdsc_pdcp_c_plane_decap(
priv->flc_desc[0].desc, 1, swap,
pdcp_xform->hfn,
+ session->pdcp.sn_size,
pdcp_xform->bearer,
pdcp_xform->pkt_dir,
pdcp_xform->hfn_threshold,
- &cipherdata, &authdata,
- 0);
+ &cipherdata, &authdata);
+
+ } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_SHORT_MAC) {
+ bufsize = cnstr_shdsc_pdcp_short_mac(priv->flc_desc[0].desc,
+ 1, swap, &authdata);
} else {
- if (session->dir == DIR_ENC)
- bufsize = cnstr_shdsc_pdcp_u_plane_encap(
+ if (session->dir == DIR_ENC) {
+ if (pdcp_xform->sdap_enabled)
+ bufsize = cnstr_shdsc_pdcp_sdap_u_plane_encap(
priv->flc_desc[0].desc, 1, swap,
- (enum pdcp_sn_size)pdcp_xform->sn_size,
+ session->pdcp.sn_size,
pdcp_xform->hfn,
pdcp_xform->bearer,
pdcp_xform->pkt_dir,
pdcp_xform->hfn_threshold,
- &cipherdata, 0);
- else if (session->dir == DIR_DEC)
- bufsize = cnstr_shdsc_pdcp_u_plane_decap(
+ &cipherdata, p_authdata);
+ else
+ bufsize = cnstr_shdsc_pdcp_u_plane_encap(
priv->flc_desc[0].desc, 1, swap,
- (enum pdcp_sn_size)pdcp_xform->sn_size,
+ session->pdcp.sn_size,
pdcp_xform->hfn,
pdcp_xform->bearer,
pdcp_xform->pkt_dir,
pdcp_xform->hfn_threshold,
- &cipherdata, 0);
+ &cipherdata, p_authdata);
+ } else if (session->dir == DIR_DEC) {
+ if (pdcp_xform->sdap_enabled)
+ bufsize = cnstr_shdsc_pdcp_sdap_u_plane_decap(
+ priv->flc_desc[0].desc, 1, swap,
+ session->pdcp.sn_size,
+ pdcp_xform->hfn,
+ pdcp_xform->bearer,
+ pdcp_xform->pkt_dir,
+ pdcp_xform->hfn_threshold,
+ &cipherdata, p_authdata);
+ else
+ bufsize = cnstr_shdsc_pdcp_u_plane_decap(
+ priv->flc_desc[0].desc, 1, swap,
+ session->pdcp.sn_size,
+ pdcp_xform->hfn,
+ pdcp_xform->bearer,
+ pdcp_xform->pkt_dir,
+ pdcp_xform->hfn_threshold,
+ &cipherdata, p_authdata);
+ }
}
if (bufsize < 0) {
flc->word1_sdl = (uint8_t)bufsize;
- /* Set EWS bit i.e. enable write-safe */
- DPAA2_SET_FLC_EWS(flc);
+ /* TODO - check the perf impact or
+ * align as per descriptor type
+ * Set EWS bit i.e. enable write-safe
+ * DPAA2_SET_FLC_EWS(flc);
+ */
+
/* Set BS = 1 i.e reuse input buffers as output buffers */
DPAA2_SET_FLC_REUSE_BS(flc);
/* Set FF = 10; reuse input buffers if they provide sufficient space */
rte_free(session->auth_key.data);
rte_free(session->cipher_key.data);
rte_free(priv);
- return -1;
+ return -EINVAL;
}
static int
rte_free(s->ctxt);
rte_free(s->cipher_key.data);
rte_free(s->auth_key.data);
- memset(sess, 0, sizeof(dpaa2_sec_session));
+ memset(s, 0, sizeof(dpaa2_sec_session));
set_sec_session_private_data(sess, NULL);
rte_mempool_put(sess_mp, sess_priv);
}
return 0;
}
-
+#endif
static int
dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
struct rte_crypto_sym_xform *xform,
return -ENOMEM;
}
- ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
+ ret = dpaa2_sec_set_session_parameters(xform, sess_private_data);
if (ret != 0) {
DPAA2_SEC_ERR("Failed to configure session parameters");
/* Return session to mempool */
rte_free(s->ctxt);
rte_free(s->cipher_key.data);
rte_free(s->auth_key.data);
- memset(sess, 0, sizeof(dpaa2_sec_session));
+ memset(s, 0, sizeof(dpaa2_sec_session));
struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
set_sym_session_private_data(sess, index, NULL);
rte_mempool_put(sess_mp, sess_priv);
PMD_INIT_FUNC_TRACE();
+ /* Change the tx burst function if ordered queues are used */
+ if (priv->en_ordered)
+ dev->enqueue_burst = dpaa2_sec_enqueue_burst_ordered;
+
memset(&attr, 0, sizeof(struct dpseci_attr));
ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
}
static int
-dpaa2_sec_dev_close(struct rte_cryptodev *dev)
+dpaa2_sec_dev_close(struct rte_cryptodev *dev __rte_unused)
{
- struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
- struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
- int ret;
-
PMD_INIT_FUNC_TRACE();
- /* Function is reverse of dpaa2_sec_dev_init.
- * It does the following:
- * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
- * 2. Close the DPSECI device
- * 3. Free the allocated resources.
- */
-
- /*Close the device at underlying layer*/
- ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
- if (ret) {
- DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
- return -1;
- }
-
- /*Free the allocated memory for ethernet private data and dpseci*/
- priv->hw = NULL;
- rte_free(dpseci);
-
return 0;
}
struct rte_cryptodev_stats *stats)
{
struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
- struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
+ struct fsl_mc_io dpseci;
struct dpseci_sec_counters counters = {0};
struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
dev->data->queue_pairs;
return;
}
for (i = 0; i < dev->data->nb_queue_pairs; i++) {
- if (qp[i] == NULL) {
+ if (qp == NULL || qp[i] == NULL) {
DPAA2_SEC_DEBUG("Uninitialised queue pair");
continue;
}
stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
}
- ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
+ /* In case as secondary process access stats, MCP portal in priv-hw
+ * may have primary process address. Need the secondary process
+ * based MCP portal address for this object.
+ */
+ dpseci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
+ ret = dpseci_get_sec_counters(&dpseci, CMD_PRI_LOW, priv->token,
&counters);
if (ret) {
DPAA2_SEC_ERR("SEC counters failed");
}
}
-static void __attribute__((hot))
+static void __rte_hot
dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
const struct qbman_fd *fd,
const struct qbman_result *dq,
struct dpaa2_queue *rxq,
struct rte_event *ev)
{
+ struct dpaa2_sec_qp *qp;
/* Prefetching mbuf */
rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
/* Prefetching ipsec crypto_op stored in priv data of mbuf */
rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
+ qp = container_of(rxq, struct dpaa2_sec_qp, rx_vq);
ev->flow_id = rxq->ev.flow_id;
ev->sub_event_type = rxq->ev.sub_event_type;
ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
ev->sched_type = rxq->ev.sched_type;
ev->queue_id = rxq->ev.queue_id;
ev->priority = rxq->ev.priority;
- ev->event_ptr = sec_fd_to_mbuf(fd, ((struct rte_cryptodev *)
- (rxq->dev))->driver_id);
+ ev->event_ptr = sec_fd_to_mbuf(fd, qp);
qbman_swp_dqrr_consume(swp, dq);
}
static void
-dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
+dpaa2_sec_process_atomic_event(struct qbman_swp *swp __rte_unused,
const struct qbman_fd *fd,
const struct qbman_result *dq,
struct dpaa2_queue *rxq,
struct rte_event *ev)
{
uint8_t dqrr_index;
- struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
+ struct dpaa2_sec_qp *qp;
+ struct rte_crypto_op *crypto_op;
/* Prefetching mbuf */
rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
/* Prefetching ipsec crypto_op stored in priv data of mbuf */
rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
+ qp = container_of(rxq, struct dpaa2_sec_qp, rx_vq);
ev->flow_id = rxq->ev.flow_id;
ev->sub_event_type = rxq->ev.sub_event_type;
ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
ev->queue_id = rxq->ev.queue_id;
ev->priority = rxq->ev.priority;
- ev->event_ptr = sec_fd_to_mbuf(fd, ((struct rte_cryptodev *)
- (rxq->dev))->driver_id);
+ crypto_op = sec_fd_to_mbuf(fd, qp);
dqrr_index = qbman_get_dqrr_idx(dq);
- crypto_op->sym->m_src->seqn = dqrr_index + 1;
+ *dpaa2_seqn(crypto_op->sym->m_src) = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
DPAA2_PER_LCORE_DQRR_SIZE++;
DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
+ ev->event_ptr = crypto_op;
+}
+
+static void __rte_hot
+dpaa2_sec_process_ordered_event(struct qbman_swp *swp,
+ const struct qbman_fd *fd,
+ const struct qbman_result *dq,
+ struct dpaa2_queue *rxq,
+ struct rte_event *ev)
+{
+ struct rte_crypto_op *crypto_op;
+ struct dpaa2_sec_qp *qp;
+
+ /* Prefetching mbuf */
+ rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
+ rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
+
+ /* Prefetching ipsec crypto_op stored in priv data of mbuf */
+ rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
+
+ qp = container_of(rxq, struct dpaa2_sec_qp, rx_vq);
+ ev->flow_id = rxq->ev.flow_id;
+ ev->sub_event_type = rxq->ev.sub_event_type;
+ ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
+ ev->op = RTE_EVENT_OP_NEW;
+ ev->sched_type = rxq->ev.sched_type;
+ ev->queue_id = rxq->ev.queue_id;
+ ev->priority = rxq->ev.priority;
+ crypto_op = sec_fd_to_mbuf(fd, qp);
+
+ *dpaa2_seqn(crypto_op->sym->m_src) = DPAA2_ENQUEUE_FLAG_ORP;
+ *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_odpid(dq) <<
+ DPAA2_EQCR_OPRID_SHIFT;
+ *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_seqnum(dq) <<
+ DPAA2_EQCR_SEQNUM_SHIFT;
+
+ qbman_swp_dqrr_consume(swp, dq);
+ ev->event_ptr = crypto_op;
}
int
dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
int qp_id,
- uint16_t dpcon_id,
+ struct dpaa2_dpcon_dev *dpcon,
const struct rte_event *event)
{
struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
struct dpseci_rx_queue_cfg cfg;
+ uint8_t priority;
int ret;
if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
+ else if (event->sched_type == RTE_SCHED_TYPE_ORDERED)
+ qp->rx_vq.cb = dpaa2_sec_process_ordered_event;
else
return -EINVAL;
+ priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
+ (dpcon->num_priorities - 1);
+
memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
cfg.options = DPSECI_QUEUE_OPT_DEST;
cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
- cfg.dest_cfg.dest_id = dpcon_id;
- cfg.dest_cfg.priority = event->priority;
+ cfg.dest_cfg.dest_id = dpcon->dpcon_id;
+ cfg.dest_cfg.priority = priority;
cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
cfg.user_ctx = (size_t)(qp);
cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
cfg.order_preservation_en = 1;
}
+
+ if (event->sched_type == RTE_SCHED_TYPE_ORDERED) {
+ struct opr_cfg ocfg;
+
+ /* Restoration window size = 256 frames */
+ ocfg.oprrws = 3;
+ /* Restoration window size = 512 frames for LX2 */
+ if (dpaa2_svr_family == SVR_LX2160A)
+ ocfg.oprrws = 4;
+ /* Auto advance NESN window enabled */
+ ocfg.oa = 1;
+ /* Late arrival window size disabled */
+ ocfg.olws = 0;
+ /* ORL resource exhaustaion advance NESN disabled */
+ ocfg.oeane = 0;
+
+ if (priv->en_loose_ordered)
+ ocfg.oloe = 1;
+ else
+ ocfg.oloe = 0;
+
+ ret = dpseci_set_opr(dpseci, CMD_PRI_LOW, priv->token,
+ qp_id, OPR_OPT_CREATE, &ocfg);
+ if (ret) {
+ RTE_LOG(ERR, PMD, "Error setting opr: ret: %d\n", ret);
+ return ret;
+ }
+ qp->tx_vq.cb_eqresp_free = dpaa2_sec_free_eqresp_buf;
+ priv->en_ordered = 1;
+ }
+
ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
qp_id, &cfg);
if (ret) {
.stats_reset = dpaa2_sec_stats_reset,
.queue_pair_setup = dpaa2_sec_queue_pair_setup,
.queue_pair_release = dpaa2_sec_queue_pair_release,
- .queue_pair_count = dpaa2_sec_queue_pair_count,
.sym_session_get_size = dpaa2_sec_sym_session_get_size,
.sym_session_configure = dpaa2_sec_sym_session_configure,
.sym_session_clear = dpaa2_sec_sym_session_clear,
+ /* Raw data-path API related operations */
+ .sym_get_raw_dp_ctx_size = dpaa2_sec_get_dp_ctx_size,
+ .sym_configure_raw_dp_ctx = dpaa2_sec_configure_raw_dp_ctx,
};
+#ifdef RTE_LIB_SECURITY
static const struct rte_security_capability *
dpaa2_sec_capabilities_get(void *device __rte_unused)
{
.set_pkt_metadata = NULL,
.capabilities_get = dpaa2_sec_capabilities_get
};
+#endif
static int
dpaa2_sec_uninit(const struct rte_cryptodev *dev)
{
- struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
+ struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
+ struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
+ int ret;
- rte_free(dev->security_ctx);
+ PMD_INIT_FUNC_TRACE();
+
+ /* Function is reverse of dpaa2_sec_dev_init.
+ * It does the following:
+ * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
+ * 2. Close the DPSECI device
+ * 3. Free the allocated resources.
+ */
- rte_mempool_free(internals->fle_pool);
+ /*Close the device at underlying layer*/
+ ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
+ if (ret) {
+ DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
+ return -1;
+ }
+
+ /*Free the allocated memory for ethernet private data and dpseci*/
+ priv->hw = NULL;
+ rte_free(dpseci);
+ rte_free(dev->security_ctx);
DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
dev->data->name, rte_socket_id());
return 0;
}
+static int
+check_devargs_handler(const char *key, const char *value,
+ void *opaque)
+{
+ struct rte_cryptodev *dev = (struct rte_cryptodev *)opaque;
+ struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
+
+ if (!strcmp(key, "drv_strict_order")) {
+ priv->en_loose_ordered = false;
+ } else if (!strcmp(key, "drv_dump_mode")) {
+ dpaa2_sec_dp_dump = atoi(value);
+ if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_FULL_DUMP) {
+ DPAA2_SEC_WARN("WARN: DPAA2_SEC_DP_DUMP_LEVEL is not "
+ "supported, changing to FULL error"
+ " prints\n");
+ dpaa2_sec_dp_dump = DPAA2_SEC_DP_FULL_DUMP;
+ }
+ } else
+ return -1;
+
+ return 0;
+}
+
+static void
+dpaa2_sec_get_devargs(struct rte_cryptodev *cryptodev, const char *key)
+{
+ struct rte_kvargs *kvlist;
+ struct rte_devargs *devargs;
+
+ devargs = cryptodev->device->devargs;
+ if (!devargs)
+ return;
+
+ kvlist = rte_kvargs_parse(devargs->args, NULL);
+ if (!kvlist)
+ return;
+
+ if (!rte_kvargs_count(kvlist, key)) {
+ rte_kvargs_free(kvlist);
+ return;
+ }
+
+ rte_kvargs_process(kvlist, key,
+ check_devargs_handler, (void *)cryptodev);
+ rte_kvargs_free(kvlist);
+}
+
static int
dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
{
struct dpaa2_sec_dev_private *internals;
struct rte_device *dev = cryptodev->device;
struct rte_dpaa2_device *dpaa2_dev;
+#ifdef RTE_LIB_SECURITY
struct rte_security_ctx *security_instance;
+#endif
struct fsl_mc_io *dpseci;
uint16_t token;
struct dpseci_attr attr;
int retcode, hw_id;
- char str[20];
PMD_INIT_FUNC_TRACE();
dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
- if (dpaa2_dev == NULL) {
- DPAA2_SEC_ERR("DPAA2 SEC device not found");
- return -1;
- }
hw_id = dpaa2_dev->object_id;
cryptodev->driver_id = cryptodev_driver_id;
RTE_CRYPTODEV_FF_HW_ACCELERATED |
RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
RTE_CRYPTODEV_FF_SECURITY |
+ RTE_CRYPTODEV_FF_SYM_RAW_DP |
RTE_CRYPTODEV_FF_IN_PLACE_SGL |
RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
DPAA2_SEC_DEBUG("Device already init by primary process");
return 0;
}
-
+#ifdef RTE_LIB_SECURITY
/* Initialize security_ctx only for primary process*/
security_instance = rte_malloc("rte_security_instances_ops",
sizeof(struct rte_security_ctx), 0);
security_instance->ops = &dpaa2_sec_security_ops;
security_instance->sess_cnt = 0;
cryptodev->security_ctx = security_instance;
-
+#endif
/*Open the rte device via MC and save the handle for further use*/
dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
sizeof(struct fsl_mc_io), 0);
if (!dpseci) {
DPAA2_SEC_ERR(
"Error in allocating the memory for dpsec object");
- return -1;
+ return -ENOMEM;
}
- dpseci->regs = rte_mcp_ptr_list[0];
+ dpseci->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
if (retcode != 0) {
retcode);
goto init_error;
}
- sprintf(cryptodev->data->name, "dpsec-%u", hw_id);
+ snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
+ "dpsec-%u", hw_id);
internals->max_nb_queue_pairs = attr.num_tx_queues;
cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
internals->hw = dpseci;
internals->token = token;
+ internals->en_loose_ordered = true;
- sprintf(str, "fle_pool_%d", cryptodev->data->dev_id);
- internals->fle_pool = rte_mempool_create((const char *)str,
- FLE_POOL_NUM_BUFS,
- FLE_POOL_BUF_SIZE,
- FLE_POOL_CACHE_SIZE, 0,
- NULL, NULL, NULL, NULL,
- SOCKET_ID_ANY, 0);
- if (!internals->fle_pool) {
- DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
- goto init_error;
- }
-
+ dpaa2_sec_get_devargs(cryptodev, DRIVER_DUMP_MODE);
+ dpaa2_sec_get_devargs(cryptodev, DRIVER_STRICT_ORDER);
DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
return 0;
int retval;
- sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id);
+ snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
+ dpaa2_dev->object_id);
cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
if (cryptodev == NULL)
/* init user callbacks */
TAILQ_INIT(&(cryptodev->link_intr_cbs));
+ if (dpaa2_svr_family == SVR_LX2160A)
+ rta_set_sec_era(RTA_SEC_ERA_10);
+ else
+ rta_set_sec_era(RTA_SEC_ERA_8);
+
+ DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
+
/* Invoke PMD device initialization function */
retval = dpaa2_sec_dev_init(cryptodev);
- if (retval == 0)
+ if (retval == 0) {
+ rte_cryptodev_pmd_probing_finish(cryptodev);
return 0;
+ }
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
rte_free(cryptodev->data->dev_private);
RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
-
-RTE_INIT(dpaa2_sec_init_log)
-{
- /* Bus level logs */
- dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
- if (dpaa2_logtype_sec >= 0)
- rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);
-}
+RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_DPAA2_SEC_PMD,
+ DRIVER_STRICT_ORDER "=<int>"
+ DRIVER_DUMP_MODE "=<int>");
+RTE_LOG_REGISTER(dpaa2_logtype_sec, pmd.crypto.dpaa2, NOTICE);