diff mbox series

[v9,20/27] ethdev: register ether layer as a class

Message ID 58a5a7ac27a6ac6206246e8534ebf67168813318.1530655929.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series Device querying | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gaëtan Rivet July 3, 2018, 10:15 p.m. UTC
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_ethdev/Makefile        |  3 +-
 lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_ethdev/rte_class_eth.c

Comments

Andrew Rybchenko July 4, 2018, 12:20 p.m. UTC | #1
On 07/04/2018 01:15 AM, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>   lib/librte_ethdev/Makefile        |  3 +-
>   lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++
>   2 files changed, 81 insertions(+), 1 deletion(-)
>   create mode 100644 lib/librte_ethdev/rte_class_eth.c
>
> diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
> index 2fa133fbc..d4c3a8d06 100644
> --- a/lib/librte_ethdev/Makefile
> +++ b/lib/librte_ethdev/Makefile
> @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
>   CFLAGS += -O3
>   CFLAGS += $(WERROR_FLAGS)
>   LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
> -LDLIBS += -lrte_mbuf
> +LDLIBS += -lrte_mbuf -lrte_kvargs
>   
>   EXPORT_MAP := rte_ethdev_version.map
>   
> @@ -20,6 +20,7 @@ LIBABIVER := 9
>   
>   SRCS-y += eth_private.c
>   SRCS-y += rte_ethdev.c
> +SRCS-y += rte_class_eth.c
>   SRCS-y += rte_flow.c
>   SRCS-y += rte_tm.c
>   SRCS-y += rte_mtr.c

meson.build files should be updated as well.
Gaëtan Rivet July 5, 2018, 9:36 a.m. UTC | #2
Hi Andrew,

On Wed, Jul 04, 2018 at 03:20:17PM +0300, Andrew Rybchenko wrote:
> On 07/04/2018 01:15 AM, Gaetan Rivet wrote:
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >   lib/librte_ethdev/Makefile        |  3 +-
> >   lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++
> >   2 files changed, 81 insertions(+), 1 deletion(-)
> >   create mode 100644 lib/librte_ethdev/rte_class_eth.c
> > 
> > diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
> > index 2fa133fbc..d4c3a8d06 100644
> > --- a/lib/librte_ethdev/Makefile
> > +++ b/lib/librte_ethdev/Makefile
> > @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
> >   CFLAGS += -O3
> >   CFLAGS += $(WERROR_FLAGS)
> >   LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
> > -LDLIBS += -lrte_mbuf
> > +LDLIBS += -lrte_mbuf -lrte_kvargs
> >   EXPORT_MAP := rte_ethdev_version.map
> > @@ -20,6 +20,7 @@ LIBABIVER := 9
> >   SRCS-y += eth_private.c
> >   SRCS-y += rte_ethdev.c
> > +SRCS-y += rte_class_eth.c
> >   SRCS-y += rte_flow.c
> >   SRCS-y += rte_tm.c
> >   SRCS-y += rte_mtr.c
> 
> meson.build files should be updated as well.

The meson version required by DPDK is not available in my distribution.
Bruce Richardson July 5, 2018, 11:13 a.m. UTC | #3
On Thu, Jul 05, 2018 at 11:36:38AM +0200, Gaëtan Rivet wrote:
> Hi Andrew,
> 
> On Wed, Jul 04, 2018 at 03:20:17PM +0300, Andrew Rybchenko wrote:
> > On 07/04/2018 01:15 AM, Gaetan Rivet wrote:
> > > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > > ---
> > >   lib/librte_ethdev/Makefile        |  3 +-
> > >   lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++
> > >   2 files changed, 81 insertions(+), 1 deletion(-)
> > >   create mode 100644 lib/librte_ethdev/rte_class_eth.c
> > > 
> > > diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
> > > index 2fa133fbc..d4c3a8d06 100644
> > > --- a/lib/librte_ethdev/Makefile
> > > +++ b/lib/librte_ethdev/Makefile
> > > @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
> > >   CFLAGS += -O3
> > >   CFLAGS += $(WERROR_FLAGS)
> > >   LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
> > > -LDLIBS += -lrte_mbuf
> > > +LDLIBS += -lrte_mbuf -lrte_kvargs
> > >   EXPORT_MAP := rte_ethdev_version.map
> > > @@ -20,6 +20,7 @@ LIBABIVER := 9
> > >   SRCS-y += eth_private.c
> > >   SRCS-y += rte_ethdev.c
> > > +SRCS-y += rte_class_eth.c
> > >   SRCS-y += rte_flow.c
> > >   SRCS-y += rte_tm.c
> > >   SRCS-y += rte_mtr.c
> > 
> > meson.build files should be updated as well.
> 
> The meson version required by DPDK is not available in my distribution.
> 
"pip3 install meson" works in just about all distros. I'd recommend using
meson from pip generally, since it tends to be very up to date. The latest
versions configure DPDK a lot faster than the older ones!

/Bruce
Gaëtan Rivet July 5, 2018, 11:54 a.m. UTC | #4
On Thu, Jul 05, 2018 at 12:13:56PM +0100, Bruce Richardson wrote:
> On Thu, Jul 05, 2018 at 11:36:38AM +0200, Gaëtan Rivet wrote:
> > Hi Andrew,
> > 
> > On Wed, Jul 04, 2018 at 03:20:17PM +0300, Andrew Rybchenko wrote:
> > > On 07/04/2018 01:15 AM, Gaetan Rivet wrote:
> > > > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > > > ---
> > > >   lib/librte_ethdev/Makefile        |  3 +-
> > > >   lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++
> > > >   2 files changed, 81 insertions(+), 1 deletion(-)
> > > >   create mode 100644 lib/librte_ethdev/rte_class_eth.c
> > > > 
> > > > diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
> > > > index 2fa133fbc..d4c3a8d06 100644
> > > > --- a/lib/librte_ethdev/Makefile
> > > > +++ b/lib/librte_ethdev/Makefile
> > > > @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
> > > >   CFLAGS += -O3
> > > >   CFLAGS += $(WERROR_FLAGS)
> > > >   LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
> > > > -LDLIBS += -lrte_mbuf
> > > > +LDLIBS += -lrte_mbuf -lrte_kvargs
> > > >   EXPORT_MAP := rte_ethdev_version.map
> > > > @@ -20,6 +20,7 @@ LIBABIVER := 9
> > > >   SRCS-y += eth_private.c
> > > >   SRCS-y += rte_ethdev.c
> > > > +SRCS-y += rte_class_eth.c
> > > >   SRCS-y += rte_flow.c
> > > >   SRCS-y += rte_tm.c
> > > >   SRCS-y += rte_mtr.c
> > > 
> > > meson.build files should be updated as well.
> > 
> > The meson version required by DPDK is not available in my distribution.
> > 
> "pip3 install meson" works in just about all distros. I'd recommend using
> meson from pip generally, since it tends to be very up to date. The latest
> versions configure DPDK a lot faster than the older ones!
> 
> /Bruce

Thanks,

The v10 now supports meson.
diff mbox series

Patch

diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
index 2fa133fbc..d4c3a8d06 100644
--- a/lib/librte_ethdev/Makefile
+++ b/lib/librte_ethdev/Makefile
@@ -12,7 +12,7 @@  CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf
+LDLIBS += -lrte_mbuf -lrte_kvargs
 
 EXPORT_MAP := rte_ethdev_version.map
 
@@ -20,6 +20,7 @@  LIBABIVER := 9
 
 SRCS-y += eth_private.c
 SRCS-y += rte_ethdev.c
+SRCS-y += rte_class_eth.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
 SRCS-y += rte_mtr.c
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
new file mode 100644
index 000000000..32c736d32
--- /dev/null
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -0,0 +1,79 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Gaëtan Rivet
+ */
+
+#include <string.h>
+
+#include <rte_class.h>
+#include <rte_compat.h>
+#include <rte_errno.h>
+#include <rte_kvargs.h>
+#include <rte_log.h>
+
+#include "rte_ethdev.h"
+#include "rte_ethdev_core.h"
+#include "eth_private.h"
+
+enum eth_params {
+	RTE_ETH_PARAMS_MAX,
+};
+
+static const char * const eth_params_keys[] = {
+	[RTE_ETH_PARAMS_MAX] = NULL,
+};
+
+struct eth_dev_match_arg {
+	struct rte_device *device;
+	struct rte_kvargs *kvlist;
+};
+
+#define eth_dev_match_arg(d, k) \
+	(&(const struct eth_dev_match_arg) { \
+		.device = (d), \
+		.kvlist = (k), \
+	})
+
+static int
+eth_dev_match(const struct rte_eth_dev *edev,
+	      const void *_arg)
+{
+	const struct eth_dev_match_arg *arg = _arg;
+	const struct rte_kvargs *kvlist = arg->kvlist;
+
+	if (edev->state == RTE_ETH_DEV_UNUSED)
+		return -1;
+	if (edev->device != arg->device)
+		return -1;
+	if (kvlist == NULL)
+		/* Empty string matches everything. */
+		return 0;
+	return 0;
+}
+
+static void *
+eth_dev_iterate(const void *start,
+		const char *str,
+		const struct rte_dev_iterator *it)
+{
+	struct rte_kvargs *kvargs = NULL;
+	struct rte_eth_dev *edev = NULL;
+
+	if (str != NULL) {
+		kvargs = rte_kvargs_parse(str, eth_params_keys);
+		if (kvargs == NULL) {
+			RTE_LOG(ERR, EAL, "cannot parse argument list\n");
+			rte_errno = EINVAL;
+			return NULL;
+		}
+	}
+	edev = eth_find_device(start, eth_dev_match,
+			       eth_dev_match_arg(it->device, kvargs));
+	rte_kvargs_free(kvargs);
+	return edev;
+}
+
+struct rte_class rte_class_eth = {
+	.dev_iterate = eth_dev_iterate,
+};
+
+RTE_REGISTER_CLASS(eth, rte_class_eth);