From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 270931BE34 for ; Tue, 26 Jun 2018 18:57:09 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id e16-v6so2752692wmd.0 for ; Tue, 26 Jun 2018 09:57:09 -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=ydSY601hq76jMizrUeFI14A1ri4rxjg+FVNkF8UBklw=; b=B4/pbq03l4aOokupEXGSh1UojhiqNZJ7LklObY7+2CxnnI1AETd063lDErT/sDwl/T KOpZpLFd+Ai1ipjDLmisFEb5ueAIJRkTNq6K9emrneIe0Ru8Fqp7Jd2OHTAmdjG1e74V r+lCs1Zji2c1n6ylAWBM62f8PUKiSTnf3gRxyQuwkQKv/7v0kB94SBoADqKNDKX4/QeH BBP43qDY+sjpUBT9KKHDdQ5FDq822eb3D+sNzNncfgDM/1EKC0mJQL6HXKD8QOJvy0/1 /6cjfuyD5AITNzZd3Vmorch8vegmuZoOFqKLU5Fp0b2Zp9L+cNumTpSaAk4UZE0N1js5 E1eQ== 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=ydSY601hq76jMizrUeFI14A1ri4rxjg+FVNkF8UBklw=; b=TiGef3SrdTjWDNKrL0+HdHSAtqMlpgBqjnD6B5ePDn5X+FrnjcOXzVjwo2taEYE33e SHXCg3KS8GqY4HAFohz3IhARlJyaHTMQLiw6nVirPsoqZ8yuJNJzSeJP2+DfU9bEeeW2 bLHWDz6Ln1A61agRDpKWenAYl7jpe/HwQNRSeOoMx2lZHK6iyJoKrXpL55Yd5hAHmKo4 HBdv1S7e7vF32QcBXH95+Y2gfpaVrNjbxdIf+7m6tSyF+5cIdv2L5nPLgmSt8WErV6rC nlWMwjTYDcPBbzQk2pddFl46ye7dX0/reCbbEnmJb13rNi09pg9ArSNvBJpWN3h+OJDX o6pw== X-Gm-Message-State: APt69E0ax9fxQ40d+Bh+OitR3ENliKiCYjhfelx0A4TUVl08EpcVgMeq x/0He1GmbbC3A9p0xIeOeB8VTUN9 X-Google-Smtp-Source: AAOMgpdH5gJgVwaVNWJnp8w1FNZtFjDuU/37TxOQ8WVnt1oCqnFpeb58z2VLfLjMEK9182pVigqUxw== X-Received: by 2002:a1c:9c4c:: with SMTP id f73-v6mr2182793wme.141.1530032228173; Tue, 26 Jun 2018 09:57:08 -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 p5-v6sm2680880wre.83.2018.06.26.09.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:06 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:17 +0200 Message-Id: <5a51d7bfcb530cf482e383cdffb07f540244c833.1530031921.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 v8 14/21] 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, 26 Jun 2018 16:57:10 -0000 Signed-off-by: Gaetan Rivet --- drivers/bus/pci/Makefile | 3 ++- drivers/bus/pci/pci_common.c | 3 +-- drivers/bus/pci/pci_params.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ drivers/bus/pci/private.h | 25 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) 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 7215aaec3..3c84207ff 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -26,8 +26,6 @@ #include "private.h" -extern struct rte_pci_bus rte_pci_bus; - #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" const char *rte_pci_get_sysfs_path(void) @@ -502,6 +500,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 88fa587e7..eafaeedc7 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; @@ -216,4 +218,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