ethdev: register as a class
authorGaetan Rivet <gaetan.rivet@6wind.com>
Wed, 19 Sep 2018 16:03:36 +0000 (18:03 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 3 Oct 2018 12:23:02 +0000 (14:23 +0200)
Implement the operators of an rte_class for the
ethdev abstraction layer.

Register the layer as such.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
lib/librte_ethdev/Makefile
lib/librte_ethdev/meson.build
lib/librte_ethdev/rte_class_eth.c [new file with mode: 0644]

index 4b0eeaa..d720dd2 100644 (file)
@@ -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 := 10
 
 SRCS-y += ethdev_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
index 7798217..172e302 100644 (file)
@@ -6,6 +6,7 @@ version = 10
 allow_experimental_apis = true
 sources = files('ethdev_private.c',
        'ethdev_profile.c',
+       'rte_class_eth.c',
        'rte_ethdev.c',
        'rte_flow.c',
        '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 (file)
index 0000000..b6557db
--- /dev/null
@@ -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 "ethdev_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);