Signed-off-by: Gaetan Rivet <gaetan.ri...@6wind.com> --- lib/Makefile | 2 +- lib/librte_ether/Makefile | 3 +- lib/librte_ether/rte_class_eth.c | 86 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 lib/librte_ether/rte_class_eth.c
diff --git a/lib/Makefile b/lib/Makefile index ec965a606..6bb6a8bed 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline DEPDIRS-librte_cmdline := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ether DEPDIRS-librte_ether := librte_net librte_eal librte_mempool librte_ring -DEPDIRS-librte_ether += librte_mbuf +DEPDIRS-librte_ether += librte_mbuf librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += librte_cryptodev diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile index 3ca5782bb..a1a0393de 100644 --- a/lib/librte_ether/Makefile +++ b/lib/librte_ether/Makefile @@ -12,13 +12,14 @@ 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 LIBABIVER := 8 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_ether/rte_class_eth.c b/lib/librte_ether/rte_class_eth.c new file mode 100644 index 000000000..bfa821d09 --- /dev/null +++ b/lib/librte_ether/rte_class_eth.c @@ -0,0 +1,86 @@ +/* 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" + +static int +eth_dev_match(struct rte_eth_dev *edev, + struct rte_kvargs *kvlist) +{ + (void) kvlist; + (void) edev; + return 0; +} + +static struct rte_device * +eth_dev_iterate(struct rte_dev_iterator *it) +{ + struct rte_eth_dev *start = it->class_device; + struct rte_kvargs *kvargs = NULL; + struct rte_eth_dev *edev = NULL; + struct rte_device *dev = NULL; + char *str = NULL; + uint16_t p = 0; + + if (it->clsstr != NULL) { + char *slash; + + str = strdup(it->clsstr); + if (str == NULL) { + RTE_LOG(ERR, EAL, "cannot allocate string copy\n"); + rte_errno = ENOMEM; + return NULL; + } + slash = strchr(str, '/'); + slash = slash ? slash : strchr(str, '\0'); + if (slash == NULL) { + RTE_LOG(ERR, EAL, "malformed string\n"); + rte_errno = EINVAL; + goto free_str; + } + slash[0] = '\0'; + kvargs = rte_kvargs_parse(str, NULL); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + goto free_str; + } + } + if (start) + p = start->data->port_id + 1; + dev = it->device; + for (p = rte_eth_find_next(p); + p < RTE_MAX_ETHPORTS; + p = rte_eth_find_next(p + 1)) { + edev = &rte_eth_devices[p]; + if (dev != edev->device) + continue; + if (eth_dev_match(edev, kvargs) == 0) { + it->class_device = edev; + goto free_str; + } + } + dev = NULL; +free_str: + if (it->clsstr != NULL) { + rte_kvargs_free(kvargs); + free(str); + } + return dev; +} + +struct rte_class rte_class_eth = { + .dev_iterate = eth_dev_iterate, +}; + +RTE_REGISTER_CLASS(eth, rte_class_eth); -- 2.11.0