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 C0D768E1C for ; Thu, 15 Mar 2018 18:50:31 +0100 (CET) Received: by mail-wr0-f194.google.com with SMTP id z12so9211053wrg.4 for ; Thu, 15 Mar 2018 10:50:31 -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=KjyScpYXaROcFAr+YIZhNPIbGJu4XtSZBs1O3Rrb26U=; b=rva/8+3jq/UqDb0AwXoDqMOIamA4JVjDtGwlA1IVeoF4XjnQ434Ay4ctrZFRLGvyCa 3AsFbpFiyz6wSRwJiH7k4rjpRpeE15xJOy+ArXUHaPJva5052JONwWXxuPBfMhYKsQ0+ ZrUq+1O/o4zTUCG/5FXjv3jDdnHRGBQ4Cz6xzqtMHRbuot7haiPs2xTX9bQOKcIFXQch oCo95t5gSGp/7mOJw4wmVg6kmY8aIPknNCRMdTMapND1rU+Ox49o8zC3gjzEq9QaErdV nWo5vL9pcSNrW9PuEMRJ2d2XuyQNa7rsvipUXXgep2X0Kgoy8/BndaPEqa5qaNmyeO9f d3BQ== 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=KjyScpYXaROcFAr+YIZhNPIbGJu4XtSZBs1O3Rrb26U=; b=N+ZGDZzOlf/GwiHMjiAL7dJvbCmk4o+qyZtSx5xlJA8H/QTFiT8yUsXt3bfZVyvE3w FmC6dQcpSJbM8OvXcAuerpmllzmgwk+LGfsvihcxaAKqQDgwLgyiXiAKmndu0kgmjtDQ twg8/ytzWBFwdGD651kE8uCB5PPRU9XdWsDFIBdxgA2AlzA+eRQ3yqeJvChriA7vLSSL GYQfJYnO0vzo5a7atkvRFCLyPaTOU7c5oVp17kB1dvkrac/3lcrNN8qKm4tKlOIpjmQL oeomabkW/i9h9kUc/6iqaKiBhxOSjPFQ3sNnTsEl3HmaMwxZPKmOyY/52fJs/9jqABJy varw== X-Gm-Message-State: AElRT7GJ4yu2cgVYcGKbE374grf3x2tpjX0IQkaOn+Fubpkxx7W66agQ InhoJAdoWVV+g+rKxhsh3J3hzwAc X-Google-Smtp-Source: AG47ELsnvVMpaaxe+N3EQZFaIlvB7mMxPpktDImVDUw/VYm5FyrS+v4R7R2zgwvxUHlJFcCFhDbeiw== X-Received: by 10.223.163.136 with SMTP id l8mr8432007wrb.270.1521136231014; Thu, 15 Mar 2018 10:50:31 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:50:29 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 15 Mar 2018 18:49:46 +0100 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 16/18] bus/vdev: implement device iteration 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:31 -0000 Signed-off-by: Gaetan Rivet --- drivers/bus/vdev/Makefile | 2 +- drivers/bus/vdev/vdev.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/bus/vdev/Makefile b/drivers/bus/vdev/Makefile index 24d424a38..52728833c 100644 --- a/drivers/bus/vdev/Makefile +++ b/drivers/bus/vdev/Makefile @@ -19,7 +19,7 @@ LIBABIVER := 1 SRCS-y += vdev.c -LDLIBS += -lrte_eal +LDLIBS += -lrte_eal -lrte_kvargs # # Export include files diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 68306f4eb..d695bdf24 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -415,6 +416,58 @@ vdev_unplug(struct rte_device *dev) return rte_vdev_uninit(dev->name); } +static int +vdev_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + + (void) kvlist; + (void) dev; + return 0; +} + +static struct rte_device * +vdev_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) { + VDEV_LOG(ERR, "could not allocate string copy\n"); + rte_errno = ENOMEM; + return NULL; + } + slash = strchr(str, '/'); + slash = slash ? slash : strchr(str, '\0'); + if (slash == NULL) { + VDEV_LOG(ERR, "malformed string\n"); + rte_errno = EINVAL; + goto free_str; + } + slash[0] = '\0'; + kvargs = rte_kvargs_parse(str, NULL); + if (kvargs == NULL) { + VDEV_LOG(ERR, "cannot parse argument list\n"); + rte_errno = EINVAL; + goto free_str; + } + } + dev = vdev_find_device(dev, vdev_dev_match, kvargs); + it->device = dev; +free_str: + if (it->busstr != NULL) { + free(str); + rte_kvargs_free(kvargs); + } + return dev; +} + static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, @@ -422,6 +475,7 @@ static struct rte_bus rte_vdev_bus = { .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .dev_iterate = vdev_dev_iterate, }; RTE_REGISTER_BUS(vdev, rte_vdev_bus); -- 2.11.0