bus: fix driver registration
[dpdk.git] / examples / ipsec-secgw / ipsec.c
index 90a9a86..0afb9d6 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -45,8 +45,9 @@
 #include "esp.h"
 
 static inline int
-create_session(struct ipsec_ctx *ipsec_ctx __rte_unused, struct ipsec_sa *sa)
+create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 {
+       struct rte_cryptodev_info cdev_info;
        unsigned long cdev_id_qp = 0;
        int32_t ret;
        struct cdev_key key = { 0 };
@@ -65,13 +66,30 @@ create_session(struct ipsec_ctx *ipsec_ctx __rte_unused, struct ipsec_sa *sa)
                return -1;
        }
 
-       RTE_LOG(DEBUG, IPSEC, "Create session for SA spi %u on cryptodev "
-                       "%u qp %u\n", sa->spi, ipsec_ctx->tbl[cdev_id_qp].id,
+       RTE_LOG_DP(DEBUG, IPSEC, "Create session for SA spi %u on cryptodev "
+                       "%u qp %u\n", sa->spi,
+                       ipsec_ctx->tbl[cdev_id_qp].id,
                        ipsec_ctx->tbl[cdev_id_qp].qp);
 
        sa->crypto_session = rte_cryptodev_sym_session_create(
-                       ipsec_ctx->tbl[cdev_id_qp].id, sa->xforms);
-
+                       ipsec_ctx->session_pool);
+       rte_cryptodev_sym_session_init(ipsec_ctx->tbl[cdev_id_qp].id,
+                       sa->crypto_session, sa->xforms,
+                       ipsec_ctx->session_pool);
+
+       rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id, &cdev_info);
+       if (cdev_info.sym.max_nb_sessions_per_qp > 0) {
+               ret = rte_cryptodev_queue_pair_attach_sym_session(
+                               ipsec_ctx->tbl[cdev_id_qp].id,
+                               ipsec_ctx->tbl[cdev_id_qp].qp,
+                               sa->crypto_session);
+               if (ret < 0) {
+                       RTE_LOG(ERR, IPSEC,
+                               "Session cannot be attached to qp %u ",
+                               ipsec_ctx->tbl[cdev_id_qp].qp);
+                       return -1;
+               }
+       }
        sa->cdev_id_qp = cdev_id_qp;
 
        return 0;
@@ -80,7 +98,7 @@ create_session(struct ipsec_ctx *ipsec_ctx __rte_unused, struct ipsec_sa *sa)
 static inline void
 enqueue_cop(struct cdev_qp *cqp, struct rte_crypto_op *cop)
 {
-       int ret, i;
+       int32_t ret, i;
 
        cqp->buf[cqp->len++] = cop;
 
@@ -88,7 +106,7 @@ enqueue_cop(struct cdev_qp *cqp, struct rte_crypto_op *cop)
                ret = rte_cryptodev_enqueue_burst(cqp->id, cqp->qp,
                                cqp->buf, cqp->len);
                if (ret < cqp->len) {
-                       RTE_LOG(DEBUG, IPSEC, "Cryptodev %u queue %u:"
+                       RTE_LOG_DP(DEBUG, IPSEC, "Cryptodev %u queue %u:"
                                        " enqueued %u crypto ops out of %u\n",
                                         cqp->id, cqp->qp,
                                         ret, cqp->len);
@@ -105,11 +123,16 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                struct rte_mbuf *pkts[], struct ipsec_sa *sas[],
                uint16_t nb_pkts)
 {
-       int ret = 0, i;
+       int32_t ret = 0, i;
        struct ipsec_mbuf_metadata *priv;
        struct ipsec_sa *sa;
 
        for (i = 0; i < nb_pkts; i++) {
+               if (unlikely(sas[i] == NULL)) {
+                       rte_pktmbuf_free(pkts[i]);
+                       continue;
+               }
+
                rte_prefetch0(sas[i]);
                rte_prefetch0(pkts[i]);
 
@@ -117,12 +140,10 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                sa = sas[i];
                priv->sa = sa;
 
-               RTE_ASSERT(sa != NULL);
-
                priv->cop.type = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
+               priv->cop.status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 
                rte_prefetch0(&priv->sym_cop);
-               priv->cop.sym = &priv->sym_cop;
 
                if ((unlikely(sa->crypto_session == NULL)) &&
                                create_session(ipsec_ctx, sa)) {
@@ -148,7 +169,7 @@ static inline int
 ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                struct rte_mbuf *pkts[], uint16_t max_pkts)
 {
-       int nb_pkts = 0, ret = 0, i, j, nb_cops;
+       int32_t nb_pkts = 0, ret = 0, i, j, nb_cops;
        struct ipsec_mbuf_metadata *priv;
        struct rte_crypto_op *cops[max_pkts];
        struct ipsec_sa *sa;