crypto/dpaa_sec: move mempool allocation to config
authorAkhil Goyal <akhil.goyal@nxp.com>
Mon, 2 Apr 2018 15:33:20 +0000 (21:03 +0530)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Mon, 23 Apr 2018 17:20:09 +0000 (18:20 +0100)
Currently, the context mempools are allocated during device probe. Thus,
even if the DPAA SEC devices are not used, any application would still
allocate the memory required for working with the contexts.

This patch moves the allocation to configuration time so that when the
CAAM devices are configured, this allocation would be done.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
Signed-off-by: Ashish Jain <ashish.jain@nxp.com>
Tested-by: Shreyansh Jain <shreyansh.jain@nxp.com>
drivers/crypto/dpaa_sec/dpaa_sec.c

index a260a11..29af781 100644 (file)
@@ -2151,11 +2151,32 @@ dpaa_sec_security_session_destroy(void *dev __rte_unused,
 
 
 static int
-dpaa_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
+dpaa_sec_dev_configure(struct rte_cryptodev *dev,
                       struct rte_cryptodev_config *config __rte_unused)
 {
+
+       char str[20];
+       struct dpaa_sec_dev_private *internals;
+
        PMD_INIT_FUNC_TRACE();
 
+       internals = dev->data->dev_private;
+       sprintf(str, "ctx_pool_%d", dev->data->dev_id);
+       if (!internals->ctx_pool) {
+               internals->ctx_pool = rte_mempool_create((const char *)str,
+                                                       CTX_POOL_NUM_BUFS,
+                                                       CTX_POOL_BUF_SIZE,
+                                                       CTX_POOL_CACHE_SIZE, 0,
+                                                       NULL, NULL, NULL, NULL,
+                                                       SOCKET_ID_ANY, 0);
+               if (!internals->ctx_pool) {
+                       RTE_LOG(ERR, PMD, "%s create failed\n", str);
+                       return -ENOMEM;
+               }
+       } else
+               RTE_LOG(INFO, PMD, "mempool already created for dev_id : %d\n",
+                       dev->data->dev_id);
+
        return 0;
 }
 
@@ -2173,9 +2194,19 @@ dpaa_sec_dev_stop(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-dpaa_sec_dev_close(struct rte_cryptodev *dev __rte_unused)
+dpaa_sec_dev_close(struct rte_cryptodev *dev)
 {
+       struct dpaa_sec_dev_private *internals;
+
        PMD_INIT_FUNC_TRACE();
+
+       if (dev == NULL)
+               return -ENOMEM;
+
+       internals = dev->data->dev_private;
+       rte_mempool_free(internals->ctx_pool);
+       internals->ctx_pool = NULL;
+
        return 0;
 }
 
@@ -2242,6 +2273,7 @@ dpaa_sec_uninit(struct rte_cryptodev *dev)
        internals = dev->data->dev_private;
        rte_free(dev->security_ctx);
 
+       /* In case close has been called, internals->ctx_pool would be NULL */
        rte_mempool_free(internals->ctx_pool);
        rte_free(internals);
 
@@ -2259,7 +2291,6 @@ dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
        struct dpaa_sec_qp *qp;
        uint32_t i, flags;
        int ret;
-       char str[20];
 
        PMD_INIT_FUNC_TRACE();
 
@@ -2319,18 +2350,6 @@ dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
                }
        }
 
-       sprintf(str, "ctx_pool_%d", cryptodev->data->dev_id);
-       internals->ctx_pool = rte_mempool_create((const char *)str,
-                       CTX_POOL_NUM_BUFS,
-                       CTX_POOL_BUF_SIZE,
-                       CTX_POOL_CACHE_SIZE, 0,
-                       NULL, NULL, NULL, NULL,
-                       SOCKET_ID_ANY, 0);
-       if (!internals->ctx_pool) {
-               RTE_LOG(ERR, PMD, "%s create failed\n", str);
-               goto init_error;
-       }
-
        PMD_INIT_LOG(DEBUG, "driver %s: created\n", cryptodev->data->name);
        return 0;