[v2] rawdev: add API to get device from index

Message ID 20241008074000.3745855-1-gakhil@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2] rawdev: add API to get device from index |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Akhil Goyal Oct. 8, 2024, 7:40 a.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>
---
- resend patch for main branch separated from rvu_lf raw driver
https://patches.dpdk.org/project/dpdk/list/?series=32949

 lib/rawdev/rte_rawdev_pmd.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
  

Comments

David Marchand Oct. 8, 2024, 11:59 a.m. UTC | #1
On Tue, Oct 8, 2024 at 9:40 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>
> ---
> - resend patch for main branch separated from rvu_lf raw driver
> https://patches.dpdk.org/project/dpdk/list/?series=32949
>
>  lib/rawdev/rte_rawdev_pmd.h | 24 ++++++++++++++++++++++++
>  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;
> +}
> +

This seems simple enough and we have the same kind of helper in other
device class libraries.
But I would like to better understand the driver API that requires this.
  
Akhil Goyal Oct. 8, 2024, noon UTC | #2
> > 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;
> > +}
> > +
> 
> This seems simple enough and we have the same kind of helper in other
> device class libraries.
> But I would like to better understand the driver API that requires this.
> 
This is being used in the new cnxk rvu_lf driver.
https://patches.dpdk.org/project/dpdk/cover/20241008105415.1026962-1-gakhil@marvell.com/
  
Hemant Agrawal Oct. 9, 2024, 6:11 a.m. UTC | #3
Reviewed-by:  Hemant Agrawal <hemant.agrawal@nxp.com>

On 08-10-2024 13:10, Akhil Goyal wrote:
> Added an internal API for PMDs to get raw device pointer
> from a device id.
>
> Signed-off-by: Akhil Goyal <gakhil@marvell.com>
> ---
> - resend patch for main branch separated from rvu_lf raw driver
> https://patches.dpdk.org/project/dpdk/list/?series=32949
>
>   lib/rawdev/rte_rawdev_pmd.h | 24 ++++++++++++++++++++++++
>   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.
>    *
  
Akhil Goyal Oct. 9, 2024, 9:13 p.m. UTC | #4
> > > 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;
> > > +}
> > > +
> >
> > This seems simple enough and we have the same kind of helper in other
> > device class libraries.
> > But I would like to better understand the driver API that requires this.
> >
> This is being used in the new cnxk rvu_lf driver.
> https://patches.dpdk.org/project/dpdk/cover/20241008105415.1026962-1-gakhil@marvell.com/

Hi David/Thomas,
Can this patch be merged in RC1, so that PMD patches can be rebased in next-net-mrvl for RC2?

-Akhil
  
Akhil Goyal Oct. 21, 2024, 10:48 a.m. UTC | #5
> Subject: RE: [EXTERNAL] Re: [PATCH v2] rawdev: add API to get device from index
> 
> > > > 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;
> > > > +}
> > > > +
> > >
> > > This seems simple enough and we have the same kind of helper in other
> > > device class libraries.
> > > But I would like to better understand the driver API that requires this.
> > >
> > This is being used in the new cnxk rvu_lf driver.
> > https://patches.dpdk.org/project/dpdk/cover/20241008105415.1026962-1-
> gakhil@marvell.com/
> 
> Hi David/Thomas,
> Can this patch be merged in RC1, so that PMD patches can be rebased in next-
> net-mrvl for RC2?
> 

Can we merge this patch early into RC2, so that PMD patch can be rebased?
  
David Marchand Oct. 22, 2024, 7:12 p.m. UTC | #6
On Tue, Oct 8, 2024 at 9:40 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>
> Reviewed-by:  Hemant Agrawal <hemant.agrawal@nxp.com>

Applied, thanks.

Can someone send a followup patch cleaning raw/cnxk_bphy and raw/ifpga
that implement a similar helper?
Cc: maintainers of those drivers.
  

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.
  *