From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id BA9A8AADD for ; Thu, 15 Mar 2018 18:50:27 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id t3so12031344wmc.2 for ; Thu, 15 Mar 2018 10:50:27 -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 :in-reply-to:references; bh=Di3hTdK5TEisnyxoyLwKevgL/8nog+r0YZA2j1/6wGw=; b=d39MtDh6OtLvg6BxwSYRH2z5LSVtl5WBvnaiwZJQZLZI1hYAxdCxqcGWSzon1s6Gkb 1PT2gGHAVfTF2Lv44IiVdmpfKe849tdv6kGvkX1bQ5MslS8+Vjwrru7QE6n0ttnuJNWi N+ysu556geeK68ykirEwkKtV+J2KEaMciYTY6V4YsZJ3UxSi/69A7aY2KDdDKT/sE/9f 72czV+oYKRm/7tx5B4rMFFosUBc1jl/u5kaO+8+DAL0Ez3zR90S5486ZfiTsqox/lwQo 1KarfYqa/1Aesjgqp6Rp2J6Ni28WE7qg83UJ3P0uY9AX+FhxxjFJkc+aKF7Qgu21De18 KdPg== 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:in-reply-to:references; bh=Di3hTdK5TEisnyxoyLwKevgL/8nog+r0YZA2j1/6wGw=; b=UD/gpGlLxmwQbt0ALM7GnSN6PSXRbcRAwgpV92z37N//hw/u66P5yBZShh2DM0RV2d hJ3AOo0fwEBI3Q3BUM/Z4iYPKalFa0XzPeJ4GWCsiItYRrTdXqmlAbwKo3eCFAbCZ0Wc 4i0Jg6YcM7u4iYg8BApE9h25VmSlaaNgzI/tqOQZkYYMGdKfTzlPSEsFs4rLSIaAOwo2 XJRohM773dJdUi/aopgfNO1BrHiND+rBmkixjoiHT0M1iS0lfWfFdPPLZoupE1QxbkUk tUWipRBIN5eiLHHycmrf1lDKwXLR1eAK3/jmRtV1YKTTsCGL/CuoMFF9SCat5jPSFobr SkaA== X-Gm-Message-State: AElRT7H/qVx/1fTd6bNXfXTpUvGDlrMSKL36bnKsPVYR2RF/U5V83klG pbZkBKSM0oUflTpRpCpDI4obpsUb X-Google-Smtp-Source: AG47ELt6HJ8Rbugufn9cldT+RJ2zjEdJEE7X0VUT0niuKzeRpv/v/p55uoT9CJMGwyTb4XujLCFiSw== X-Received: by 10.28.0.88 with SMTP id 85mr5286044wma.63.1521136227045; Thu, 15 Mar 2018 10:50:27 -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 69sm4756596wmp.36.2018.03.15.10.50.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:50:26 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 15 Mar 2018 18:49:43 +0100 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 13/18] 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: Thu, 15 Mar 2018 17:50:27 -0000 Signed-off-by: Gaetan Rivet --- drivers/bus/pci/Makefile | 2 +- drivers/bus/pci/pci_common.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/bus/pci/Makefile b/drivers/bus/pci/Makefile index f3df1c4ce..73498dc77 100644 --- a/drivers/bus/pci/Makefile +++ b/drivers/bus/pci/Makefile @@ -50,7 +50,7 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal 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)) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 2c45f8151..482c96df2 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -497,6 +498,58 @@ pci_unplug(struct rte_device *dev) return ret; } +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; +} + +static struct rte_device * +pci_dev_iterate(struct rte_dev_iterator *it) +{ + struct rte_device *dev = it->device; + struct rte_kvargs *kvargs = NULL; + char *str = NULL; + + if (it->busstr != NULL) { + char *slash; + + str = strdup(it->busstr); + if (str == NULL) { + RTE_LOG(ERR, EAL, "could not 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; + } + } + dev = pci_find_device(dev, pci_dev_match, kvargs); + it->device = dev; +free_str: + if (it->busstr != NULL) { + free(str); + rte_kvargs_free(kvargs); + } + return dev; +} + struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, @@ -506,6 +559,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .dev_iterate = pci_dev_iterate, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), -- 2.11.0