[1/9] rawdev: add API to get device from index

Message ID 20240907193311.1342310-2-gakhil@marvell.com (mailing list archive)
State Changes Requested
Delegated to: Jerin Jacob
Headers
Series drivers/raw: introduce cnxk rvu lf device driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Akhil Goyal Sept. 7, 2024, 7:33 p.m. UTC
Added an internal API for PMDs to get raw device pointer
from a device id.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 lib/rawdev/rte_rawdev_pmd.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
  

Comments

Jerin Jacob Sept. 23, 2024, 3:23 p.m. UTC | #1
On Sun, Sep 8, 2024 at 1:03 AM Akhil Goyal <gakhil@marvell.com> wrote:
>
> Added an internal API for PMDs to get raw device pointer
> from a device id.
>
> Signed-off-by: Akhil Goyal <gakhil@marvell.com>
> ---
>  lib/rawdev/rte_rawdev_pmd.h | 24 ++++++++++++++++++++++++

# This patch needs to go through the main tree. So please send this
separate patch and rest of the patch as separate series.
# verion.map update is missing for new API as INTERNAL section.



>  1 file changed, 24 insertions(+)
>
> diff --git a/lib/rawdev/rte_rawdev_pmd.h b/lib/rawdev/rte_rawdev_pmd.h
> index 22b406444d..8339122348 100644
> --- a/lib/rawdev/rte_rawdev_pmd.h
> +++ b/lib/rawdev/rte_rawdev_pmd.h
> @@ -102,6 +102,30 @@ rte_rawdev_pmd_get_named_dev(const char *name)
>         return NULL;
>  }
>
> +/**
> + * Get the rte_rawdev structure device pointer for given device ID.
> + *
> + * @param dev_id
> + *   raw device index.
> + *
> + * @return
> + *   - The rte_rawdev structure pointer for the given device ID.
> + */
> +static inline struct rte_rawdev *
> +rte_rawdev_pmd_get_dev(uint8_t dev_id)
> +{
> +       struct rte_rawdev *dev;
> +
> +       if (dev_id >= RTE_RAWDEV_MAX_DEVS)
> +               return NULL;
> +
> +       dev = &rte_rawdevs[dev_id];
> +       if (dev->attached == RTE_RAWDEV_ATTACHED)
> +               return dev;
> +
> +       return NULL;
> +}
> +
>  /**
>   * Validate if the raw device index is a valid attached raw device.
>   *
> --
> 2.25.1
>
  

Patch

diff --git a/lib/rawdev/rte_rawdev_pmd.h b/lib/rawdev/rte_rawdev_pmd.h
index 22b406444d..8339122348 100644
--- a/lib/rawdev/rte_rawdev_pmd.h
+++ b/lib/rawdev/rte_rawdev_pmd.h
@@ -102,6 +102,30 @@  rte_rawdev_pmd_get_named_dev(const char *name)
 	return NULL;
 }
 
+/**
+ * Get the rte_rawdev structure device pointer for given device ID.
+ *
+ * @param dev_id
+ *   raw device index.
+ *
+ * @return
+ *   - The rte_rawdev structure pointer for the given device ID.
+ */
+static inline struct rte_rawdev *
+rte_rawdev_pmd_get_dev(uint8_t dev_id)
+{
+	struct rte_rawdev *dev;
+
+	if (dev_id >= RTE_RAWDEV_MAX_DEVS)
+		return NULL;
+
+	dev = &rte_rawdevs[dev_id];
+	if (dev->attached == RTE_RAWDEV_ATTACHED)
+		return dev;
+
+	return NULL;
+}
+
 /**
  * Validate if the raw device index is a valid attached raw device.
  *