]> git.droids-corp.org - dpdk.git/commitdiff
crypto/octeontx: add global resource init
authorAnoob Joseph <anoob.joseph@caviumnetworks.com>
Tue, 9 Oct 2018 09:07:39 +0000 (14:37 +0530)
committerAkhil Goyal <akhil.goyal@nxp.com>
Wed, 17 Oct 2018 10:20:06 +0000 (12:20 +0200)
Adding initialization of global resources. This will be saved as
metadata in cptvf and would be used by common code. Exit path for
failure case is also added along with the new routines.

Signed-off-by: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
Signed-off-by: Murthy NSSR <nidadavolu.murthy@caviumnetworks.com>
Signed-off-by: Nithin Dabilpuram <nithin.dabilpuram@caviumnetworks.com>
Signed-off-by: Ragothaman Jayaraman <rjayaraman@caviumnetworks.com>
Signed-off-by: Srisivasubramanian S <ssrinivasan@caviumnetworks.com>
Signed-off-by: Tejasree Kondoj <kondoj.tejasree@caviumnetworks.com>
drivers/crypto/octeontx/Makefile
drivers/crypto/octeontx/meson.build
drivers/crypto/octeontx/otx_cryptodev.c
drivers/crypto/octeontx/otx_cryptodev_hw_access.c
drivers/crypto/octeontx/otx_cryptodev_hw_access.h
drivers/crypto/octeontx/otx_cryptodev_ops.c
drivers/crypto/octeontx/otx_cryptodev_ops.h

index d7554417940d20c20c53ba483e0fa12b63e08d2f..1808244a5f59520e26721918512c69f495067396 100644 (file)
@@ -16,6 +16,7 @@ CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
 LDLIBS += -lrte_cryptodev
 LDLIBS += -lrte_pci -lrte_bus_pci
+LDLIBS += -lrte_common_cpt
 
 VPATH += $(RTE_SDK)/drivers/crypto/octeontx
 
index 4c5a40c729db1655dd461040768346c1db7c96bd..7f65476285789cf883f17016ff977ddc1b6edfb4 100644 (file)
@@ -5,6 +5,7 @@ if host_machine.system() != 'linux'
 endif
 
 deps += ['bus_pci']
+deps += ['common_cpt']
 name = 'octeontx_crypto'
 
 sources = files('otx_cryptodev.c',
@@ -12,5 +13,5 @@ sources = files('otx_cryptodev.c',
                'otx_cryptodev_hw_access.c',
                'otx_cryptodev_ops.c')
 
-cflags += '-DCPT_MODEL=CRYPTO_OCTEONTX'
 includes += include_directories('../../common/cpt')
+cflags += '-DCPT_MODEL=CRYPTO_OCTEONTX'
index 43933ddf0ddc59c15a39b46af7502f4efccfeeb7..269f0456bd08c394d58bbbabcc6cdcfc8e525d68 100644 (file)
@@ -104,6 +104,9 @@ otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
        cryptodev->device->driver = NULL;
        cryptodev->data = NULL;
 
+       /* free metapool memory */
+       cleanup_global_resources();
+
        return 0;
 }
 
index 369d62b3d8a4b0764cbdfae99502ee1d024d666a..e8a2b0b0dbaa06db3e6956ba44ad110456cd3e50 100644 (file)
@@ -236,3 +236,14 @@ otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name)
 
        return 0;
 }
+
+int
+otx_cpt_deinit_device(void *dev)
+{
+       struct cpt_vf *cptvf = (struct cpt_vf *)dev;
+
+       /* Do misc work one last time */
+       otx_cpt_poll_misc(cptvf);
+
+       return 0;
+}
index 73473edcb35d633198529124feeda93331e975b4..6e5731a00b6fe87133c76d89edbd0d9a1c87f582 100644 (file)
@@ -142,4 +142,7 @@ otx_cpt_poll_misc(struct cpt_vf *cptvf);
 int
 otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name);
 
+int
+otx_cpt_deinit_device(void *dev);
+
 #endif /* _OTX_CRYPTODEV_HW_ACCESS_H_ */
index 3bf6cd29f7de5b135101d0b49f0298d4ceafc51b..68c6b927a69dfc99e1e7fa468f8c03242b310389 100644 (file)
@@ -8,11 +8,69 @@
 #include <rte_malloc.h>
 
 #include "cpt_pmd_logs.h"
+#include "cpt_pmd_ops_helper.h"
 
 #include "otx_cryptodev.h"
 #include "otx_cryptodev_hw_access.h"
 #include "otx_cryptodev_ops.h"
 
+static int otx_cryptodev_probe_count;
+static rte_spinlock_t otx_probe_count_lock = RTE_SPINLOCK_INITIALIZER;
+
+static struct rte_mempool *otx_cpt_meta_pool;
+static int otx_cpt_op_mlen;
+static int otx_cpt_op_sb_mlen;
+
+/*
+ * Initializes global variables used by fast-path code
+ *
+ * @return
+ *   - 0 on success, errcode on error
+ */
+static int
+init_global_resources(void)
+{
+       /* Get meta len for scatter gather mode */
+       otx_cpt_op_mlen = cpt_pmd_ops_helper_get_mlen_sg_mode();
+
+       /* Extra 4B saved for future considerations */
+       otx_cpt_op_mlen += 4 * sizeof(uint64_t);
+
+       otx_cpt_meta_pool = rte_mempool_create("cpt_metabuf-pool", 4096 * 16,
+                                              otx_cpt_op_mlen, 512, 0,
+                                              NULL, NULL, NULL, NULL,
+                                              SOCKET_ID_ANY, 0);
+       if (!otx_cpt_meta_pool) {
+               CPT_LOG_ERR("cpt metabuf pool not created");
+               return -ENOMEM;
+       }
+
+       /* Get meta len for direct mode */
+       otx_cpt_op_sb_mlen = cpt_pmd_ops_helper_get_mlen_direct_mode();
+
+       /* Extra 4B saved for future considerations */
+       otx_cpt_op_sb_mlen += 4 * sizeof(uint64_t);
+
+       return 0;
+}
+
+void
+cleanup_global_resources(void)
+{
+       /* Take lock */
+       rte_spinlock_lock(&otx_probe_count_lock);
+
+       /* Decrement the cryptodev count */
+       otx_cryptodev_probe_count--;
+
+       /* Free buffers */
+       if (otx_cpt_meta_pool && otx_cryptodev_probe_count == 0)
+               rte_mempool_free(otx_cpt_meta_pool);
+
+       /* Free lock */
+       rte_spinlock_unlock(&otx_probe_count_lock);
+}
+
 /* Alarm routines */
 
 static void
@@ -31,6 +89,20 @@ otx_cpt_periodic_alarm_start(void *arg)
                                 otx_cpt_alarm_cb, arg);
 }
 
+static int
+otx_cpt_periodic_alarm_stop(void *arg)
+{
+       return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg);
+}
+
+static void
+otx_cpt_common_vars_init(struct cpt_vf *cptvf)
+{
+       cptvf->meta_info.cptvf_meta_pool = otx_cpt_meta_pool;
+       cptvf->meta_info.cptvf_op_mlen = otx_cpt_op_mlen;
+       cptvf->meta_info.cptvf_op_sb_mlen = otx_cpt_op_sb_mlen;
+}
+
 int
 otx_cpt_dev_create(struct rte_cryptodev *c_dev)
 {
@@ -78,6 +150,20 @@ otx_cpt_dev_create(struct rte_cryptodev *c_dev)
        /* Start off timer for mailbox interrupts */
        otx_cpt_periodic_alarm_start(cptvf);
 
+       rte_spinlock_lock(&otx_probe_count_lock);
+       if (!otx_cryptodev_probe_count) {
+               ret = init_global_resources();
+               if (ret) {
+                       rte_spinlock_unlock(&otx_probe_count_lock);
+                       goto init_fail;
+               }
+       }
+       otx_cryptodev_probe_count++;
+       rte_spinlock_unlock(&otx_probe_count_lock);
+
+       /* Initialize data path variables used by common code */
+       otx_cpt_common_vars_init(cptvf);
+
        c_dev->dev_ops = NULL;
 
        c_dev->enqueue_burst = NULL;
@@ -95,6 +181,10 @@ otx_cpt_dev_create(struct rte_cryptodev *c_dev)
 
        return 0;
 
+init_fail:
+       otx_cpt_periodic_alarm_stop(cptvf);
+       otx_cpt_deinit_device(cptvf);
+
 fail:
        if (cptvf) {
                /* Free private data allocated */
index 3f2d8291a7c02f8bc1d38a586f2cffaf9e34a123..ac88fa5753c8a843e0f8e769052f5a12798053b4 100644 (file)
@@ -5,6 +5,9 @@
 #ifndef _OTX_CRYPTODEV_OPS_H_
 #define _OTX_CRYPTODEV_OPS_H_
 
+void
+cleanup_global_resources(void);
+
 int
 otx_cpt_dev_create(struct rte_cryptodev *c_dev);