- rte_cryptodev_driver/rte_cryptodev_dev embeds rte_soc_driver/device for
  linking SoC PMDs to crypto devices.
- Add probe and remove functions linked

Signed-off-by: Hemant Agrawal <hemant.agrawal at nxp.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain at nxp.com>
---
 lib/librte_cryptodev/rte_cryptodev.c           | 122 ++++++++++++++++++++++++-
 lib/librte_cryptodev/rte_cryptodev.h           |   3 +
 lib/librte_cryptodev/rte_cryptodev_pmd.h       |  18 +++-
 lib/librte_cryptodev/rte_cryptodev_version.map |   2 +
 4 files changed, 140 insertions(+), 5 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c 
b/lib/librte_cryptodev/rte_cryptodev.c
index 127e8d0..77ec9fe 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -422,7 +422,8 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,

        int retval;

-       cryptodrv = (struct rte_cryptodev_driver *)pci_drv;
+       cryptodrv = container_of(pci_drv, struct rte_cryptodev_driver,
+                                pci_drv);
        if (cryptodrv == NULL)
                return -ENODEV;

@@ -489,7 +490,8 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
        if (cryptodev == NULL)
                return -ENODEV;

-       cryptodrv = (const struct rte_cryptodev_driver *)pci_dev->driver;
+       cryptodrv = container_of(pci_dev->driver, struct rte_cryptodev_driver,
+                                pci_drv);
        if (cryptodrv == NULL)
                return -ENODEV;

@@ -513,6 +515,111 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
        return 0;
 }

+
+int
+rte_cryptodev_soc_probe(struct rte_soc_driver *soc_drv,
+                     struct rte_soc_device *soc_dev)
+{
+       struct rte_cryptodev_driver *cryptodrv;
+       struct rte_cryptodev *cryptodev;
+
+       char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
+
+       int retval;
+
+       cryptodrv = container_of(soc_drv, struct rte_cryptodev_driver,
+                                soc_drv);
+
+       rte_eal_soc_device_name(&soc_dev->addr, cryptodev_name,
+                       sizeof(cryptodev_name));
+
+       cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name,
+                                              rte_socket_id());
+       if (cryptodev == NULL)
+               return -ENOMEM;
+
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+               cryptodev->data->dev_private =
+                               rte_zmalloc_socket(
+                                               "cryptodev private structure",
+                                               cryptodrv->dev_private_size,
+                                               RTE_CACHE_LINE_SIZE,
+                                               rte_socket_id());
+
+               if (cryptodev->data->dev_private == NULL)
+                       rte_panic("Cannot allocate memzone for private "
+                                       "device data");
+       }
+
+       cryptodev->soc_dev = soc_dev;
+       cryptodev->driver = cryptodrv;
+
+       /* init user callbacks */
+       TAILQ_INIT(&(cryptodev->link_intr_cbs));
+
+       /* Invoke PMD device initialization function */
+       retval = (*cryptodrv->cryptodev_init)(cryptodrv, cryptodev);
+       if (retval == 0)
+               return 0;
+
+       CDEV_LOG_ERR("driver %s: cryptodev_init(%s) failed\n",
+                       soc_drv->driver.name,
+                       soc_dev->addr.name);
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               rte_free(cryptodev->data->dev_private);
+
+       cryptodev->attached = RTE_CRYPTODEV_DETACHED;
+       cryptodev_globals.nb_devs--;
+
+       return -ENXIO;
+}
+
+int
+rte_cryptodev_soc_remove(struct rte_soc_device *soc_dev)
+{
+       const struct rte_cryptodev_driver *cryptodrv;
+       struct rte_cryptodev *cryptodev;
+       char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
+       int ret;
+
+       if (soc_dev == NULL)
+               return -EINVAL;
+
+       rte_eal_soc_device_name(&soc_dev->addr, cryptodev_name,
+                       sizeof(cryptodev_name));
+
+       cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
+       if (cryptodev == NULL)
+               return -ENODEV;
+
+       cryptodrv = container_of(soc_dev->driver,
+               struct rte_cryptodev_driver, soc_drv);
+       if (cryptodrv == NULL)
+               return -ENODEV;
+
+       /* Invoke PMD device uninit function */
+       if (*cryptodrv->cryptodev_uninit) {
+               ret = (*cryptodrv->cryptodev_uninit)(cryptodrv, cryptodev);
+               if (ret)
+                       return ret;
+       }
+
+       /* free crypto device */
+       rte_cryptodev_pmd_release_device(cryptodev);
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               rte_free(cryptodev->data->dev_private);
+
+       cryptodev->pci_dev = NULL;
+       cryptodev->soc_dev = NULL;
+       cryptodev->driver = NULL;
+       cryptodev->data = NULL;
+
+       return 0;
+}
+
 uint16_t
 rte_cryptodev_queue_pair_count(uint8_t dev_id)
 {
@@ -868,8 +975,15 @@ rte_cryptodev_info_get(uint8_t dev_id, struct 
rte_cryptodev_info *dev_info)
        (*dev->dev_ops->dev_infos_get)(dev, dev_info);

        dev_info->pci_dev = dev->pci_dev;
-       if (dev->driver)
-               dev_info->driver_name = dev->driver->pci_drv.driver.name;
+       dev_info->soc_dev = dev->soc_dev;
+       if (dev->driver) {
+               if (dev->soc_dev)
+                       dev_info->driver_name
+                               = dev->driver->soc_drv.driver.name;
+               else
+                       dev_info->driver_name
+                               = dev->driver->pci_drv.driver.name;
+       }
 }


diff --git a/lib/librte_cryptodev/rte_cryptodev.h 
b/lib/librte_cryptodev/rte_cryptodev.h
index 232f34a..b94188d 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -244,6 +244,7 @@ struct rte_cryptodev_info {
        const char *driver_name;                /**< Driver name. */
        enum rte_cryptodev_type dev_type;       /**< Device type */
        struct rte_pci_device *pci_dev;         /**< PCI information. */
+       struct rte_soc_device *soc_dev;         /**< SoC information. */

        uint64_t feature_flags;                 /**< Feature flags */

@@ -623,6 +624,8 @@ struct rte_cryptodev {
        /**< Supported features */
        struct rte_pci_device *pci_dev;
        /**< PCI info. supplied by probing */
+       struct rte_soc_device *soc_dev;
+       /**< SoC info. supplied by probing/Scanning */

        enum rte_cryptodev_type dev_type;
        /**< Crypto device type */
diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h 
b/lib/librte_cryptodev/rte_cryptodev_pmd.h
index abfe2dc..a8af2ce 100644
--- a/lib/librte_cryptodev/rte_cryptodev_pmd.h
+++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h
@@ -48,6 +48,7 @@ extern "C" {

 #include <rte_dev.h>
 #include <rte_pci.h>
+#include <rte_soc.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
@@ -131,7 +132,8 @@ typedef int (*cryptodev_uninit_t)(const struct 
rte_cryptodev_driver  *drv,
  * - The size of the private data to allocate for each matching device.
  */
 struct rte_cryptodev_driver {
-       struct rte_pci_driver pci_drv;  /**< The PMD is also a PCI driver. */
+       struct rte_pci_driver pci_drv;  /**< The PMD is PCI type driver. */
+       struct rte_soc_driver soc_drv;  /**< The PMD is SoC type driver. */
        unsigned dev_private_size;      /**< Size of device private data. */

        cryptodev_init_t cryptodev_init;        /**< Device init function. */
@@ -519,6 +521,20 @@ int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
  */
 int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);

+/**
+ * Wrapper for use by SoC drivers as a .devinit function to attach to a
+ * cryptodev interface.
+ */
+int rte_cryptodev_soc_probe(struct rte_soc_driver *soc_drv,
+                         struct rte_soc_device *soc_dev);
+
+/**
+ * Wrapper for use by SoC drivers as a .devuninit function to detach a
+ * cryptodev interface.
+ */
+int rte_cryptodev_soc_remove(struct rte_soc_device *soc_dev);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map 
b/lib/librte_cryptodev/rte_cryptodev_version.map
index 9dde0e7..d81073e 100644
--- a/lib/librte_cryptodev/rte_cryptodev_version.map
+++ b/lib/librte_cryptodev/rte_cryptodev_version.map
@@ -44,5 +44,7 @@ DPDK_16.11 {

        rte_cryptodev_pci_probe;
        rte_cryptodev_pci_remove;
+       rte_cryptodev_soc_probe;
+       rte_cryptodev_soc_remove;

 } DPDK_16.07;
-- 
2.7.4

Reply via email to