From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id 8D9A91BE8E for ; Wed, 4 Jul 2018 00:15:54 +0200 (CEST) Received: by mail-wr0-f194.google.com with SMTP id r16-v6so252094wrt.11 for ; Tue, 03 Jul 2018 15:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=ZA0pz5764HLLjXKe1GWiXzpsCYylgzuh/27TrMnFKsw=; b=bunU5yNN1kzNZHL/aDGyyWRCgIycvnKLmL1RIbSzSQB1oRoXUBcojId2aHswbvMW5m ad/5kjdha0SZdDicaNp/hN3Tuvhl4lOHwMF3yQJc77sVbIHtSCSo4WEM+7Ly7jVB8EDF p7FU8XswewjgDgKqzcn1XgQn8mP8Lx4MigSRakVrqZY/BUx2tu8NArKSZqlZgMXpAvNH SxL9w3LU89tY5rZFieAZme7yisunJpByqKe63LWoB6DbaQScTGDcZFGfA509IlLKj4Jl hVwLDzmLjMkLsEjq3ciX9jB6wwgejLF9jAnDTSJJxgEi4Qhi2PLWsksSHxYZb4ChZL9o zNCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=ZA0pz5764HLLjXKe1GWiXzpsCYylgzuh/27TrMnFKsw=; b=P6efIvtjf8MF2V07vKajuBFHVbHATkRSu3cGEG/M5qgM1MvlQfhYK+Y6cW/Sg0dSwd +009/CUW579LdX+q8vWWOp+bxecGI6FlC9xK6DjfPhYuZbZjPOn970I//duUHvTLaojw spEUPjHAQ+7cW2zsldeurgqZZCXPx1cQHGcoJmwTbihNB1/cRlLSSA0X74wSjcV7WQFU Y3q06FSt40huu66cEiPNrzQNmfgB16ZP5AkTjt81swInUkZvUR2iMLGl9qFr7bfII6pl XLavu6MUVXuXHb1vR1fyJkHPJGsQBBgCEcKm+lvn5slFzyS98VGQOAddBOI+E1OstYUH kkvw== X-Gm-Message-State: APt69E32Lpct/NS6+qWec4XVtz6xykz+O3JNTOho/qRIYLID54TQNY9z vFK9RH8k6Sbse6K8os4wnQJy+D3o X-Google-Smtp-Source: AAOMgpeW/IKVwBp3wlFffWTVwDh5HZn/mvfgVWMdnWfM0Sp/vBvOIF4joQQS444Ic0zdCHPRt7oyMg== X-Received: by 2002:adf:f086:: with SMTP id n6-v6mr13303955wro.49.1530656153948; Tue, 03 Jul 2018 15:15:53 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id i190-v6sm3771084wmd.33.2018.07.03.15.15.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 15:15:53 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 4 Jul 2018 00:14:58 +0200 Message-Id: <538a47f24ec47d61b58a3b8c686b209946b1e483.1530655929.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v9 15/27] bus/pci: implement device iteration and comparison X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 22:15:55 -0000 Signed-off-by: Gaetan Rivet --- drivers/bus/pci/Makefile | 3 ++- drivers/bus/pci/pci_common.c | 1 + drivers/bus/pci/pci_params.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ drivers/bus/pci/private.h | 25 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 drivers/bus/pci/pci_params.c diff --git a/drivers/bus/pci/Makefile b/drivers/bus/pci/Makefile index cf373068a..4de953f8f 100644 --- a/drivers/bus/pci/Makefile +++ b/drivers/bus/pci/Makefile @@ -26,10 +26,11 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring -LDLIBS += -lrte_ethdev -lrte_pci +LDLIBS += -lrte_ethdev -lrte_pci -lrte_kvargs include $(RTE_SDK)/drivers/bus/pci/$(SYSTEM)/Makefile SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) := $(addprefix $(SYSTEM)/,$(SRCS)) +SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_params.c SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_common.c SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_common_uio.c diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 94b0f4143..749b6eee3 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -437,6 +437,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .dev_iterate = rte_pci_dev_iterate, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c new file mode 100644 index 000000000..0fde75803 --- /dev/null +++ b/drivers/bus/pci/pci_params.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaƫtan Rivet + */ + +#include +#include +#include +#include +#include + +#include "private.h" + +enum pci_params { + RTE_PCI_PARAMS_MAX, +}; + +static const char * const pci_params_keys[] = { + [RTE_PCI_PARAMS_MAX] = NULL, +}; + +static int +pci_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + + (void) dev; + (void) kvlist; + return 0; +} + +void * +rte_pci_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it __rte_unused) +{ + rte_bus_find_device_t find_device; + struct rte_kvargs *kvargs = NULL; + struct rte_device *dev; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, pci_params_keys); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + return NULL; + } + } + find_device = rte_pci_bus.bus.find_device; + dev = find_device(start, pci_dev_match, kvargs); + rte_kvargs_free(kvargs); + return dev; +} diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index 8ddd03e16..0e689fa74 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -10,6 +10,8 @@ #include #include +extern struct rte_pci_bus rte_pci_bus; + struct rte_pci_driver; struct rte_pci_device; @@ -166,4 +168,27 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, enum rte_iova_mode rte_pci_get_iommu_class(void); +/* + * Iterate over internal devices, + * matching any device against the provided + * string. + * + * @param start + * Iteration starting point. + * + * @param str + * Device string to match against. + * + * @param it + * (unused) iterator structure. + * + * @return + * A pointer to the next matching device if any. + * NULL otherwise. + */ +void * +rte_pci_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it); + #endif /* _PCI_PRIVATE_H_ */ -- 2.11.0