From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com
 [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 26B4C1B523
 for <dev@dpdk.org>; Wed, 11 Jul 2018 23:46:06 +0200 (CEST)
Received: by mail-wr1-f67.google.com with SMTP id r16-v6so19601557wrt.11
 for <dev@dpdk.org>; Wed, 11 Jul 2018 14:46:06 -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:content-transfer-encoding;
 bh=UCDR0M0DtcuI3oK7gjdz+Az6MHSirgQY9BaN5ez27SQ=;
 b=E4QmPdHUtHAlzrd53hAHA+JmEz/0/fsWGvEoujKSQBd1D62MW2WNXFIaBly6GBsQdR
 bGbIAKZCkNgBPa376G0+sOYUDIwpGN/tUwnH+uc6syJ1YE8vg8kbSbv6qQ/WX8fOqhdo
 5j+2hIOYTxd4vRV5B9/pugMgGhf6q2B5uygRwbnXm/tDbKDhUWHgPU6CaTS8BkzFMhIW
 /Qu5EG18hvKLoP/nxlHiPuAP/cHw/upDKGrPn1AF94dGq8vBoihKXho5jBkaYsr0S+Ab
 yySEpIGYWC5+SOhe2D7iJ11UaUu7T7sm7x5FZ+Ax873wbJ+0Olequzwx8/WiihOkQuQ/
 c2iw==
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:content-transfer-encoding;
 bh=UCDR0M0DtcuI3oK7gjdz+Az6MHSirgQY9BaN5ez27SQ=;
 b=TNkdJTsGIeB5hNDHJdTwjJ1FhecmEeWt/aI/EtpaTC/PcESNs/JxZV/FwVGNYbLqro
 9H6OB4+jWDFIbMad5qcxt1Nb8QvlG8GKVtXFa6G5X+LMl7grbqoVgngdXvPd971O6+/j
 ytfIp/2nvvjKkLwOyS+pMAgKViO55mked+zSemESOL32JAkZH6qaonJhUnb5j5FcwfWi
 9XggJtjQcd2y0MKwZfPHp+TWvLFFd3OJRvgp7l2XodBPqCS/jZIDWTNSn6wMErCi2iRR
 NwCliEUdJtovsOziXIRFtFwMGwPkV7Pd9Qq0T5C+wu+cO4CluPHNAT3ETd9WvnUINiPQ
 GZYQ==
X-Gm-Message-State: AOUpUlEXHothVinMhrzugD4MSbN+YwXzOLhszapCvrKJn4EWJkY3Y7dy
 wlFKUV8/23P55k7SyCkeIRcyYDo1
X-Google-Smtp-Source: AAOMgpdHEZpmuolHbU8Bd8HNIcn+pWkByxEYXSEmsA+HXbxt9RkVbWY+b0wvCa0mz8kGTnZi4ztgLA==
X-Received: by 2002:a5d:4d8d:: with SMTP id b13-v6mr214956wru.80.1531345565220; 
 Wed, 11 Jul 2018 14:46:05 -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 h5-v6sm10550936wrr.19.2018.07.11.14.46.03
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 11 Jul 2018 14:46:04 -0700 (PDT)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Date: Wed, 11 Jul 2018 23:45:12 +0200
Message-Id: <ae232bc787580f1dabb57b4432714575f746c400.1531345404.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.18.0
In-Reply-To: <cover.1531345404.git.gaetan.rivet@6wind.com>
References: <cover.1531345404.git.gaetan.rivet@6wind.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v11 22/25] bus/vdev: pre-process declarative vdev
	devargs
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 11 Jul 2018 21:46:06 -0000

The new devargs format does not recognize a particular device name.
Each bus uses its specific format.

Process each devargs privately prior to attempting a bus scan.
Prepare them if they are using the new devargs format.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 drivers/bus/vdev/vdev.c         | 10 ++++---
 drivers/bus/vdev/vdev_params.c  | 50 +++++++++++++++++++++++++++++++++
 drivers/bus/vdev/vdev_private.h |  6 ++++
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index e8518833d..f2dace245 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -115,8 +115,8 @@ rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg)
 	return 0;
 }
 
-static int
-vdev_parse(const char *name, void *addr)
+int
+rte_vdev_parse(const char *name, void *addr)
 {
 	struct rte_vdev_driver **out = addr;
 	struct rte_vdev_driver *driver = NULL;
@@ -148,7 +148,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 	VDEV_LOG(DEBUG, "Search driver %s to probe device %s", name,
 		rte_vdev_device_name(dev));
 
-	if (vdev_parse(name, &driver))
+	if (rte_vdev_parse(name, &driver))
 		return -1;
 	dev->device.driver = &driver->driver;
 	ret = driver->probe(dev);
@@ -443,6 +443,8 @@ vdev_scan(void)
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
 	RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+		if (rte_vdev_devargs_prepare(devargs))
+			continue;
 
 		dev = calloc(1, sizeof(*dev));
 		if (!dev)
@@ -536,7 +538,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = rte_vdev_find_device,
 	.plug = vdev_plug,
 	.unplug = vdev_unplug,
-	.parse = vdev_parse,
+	.parse = rte_vdev_parse,
 	.dev_iterate = rte_vdev_dev_iterate,
 };
 
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
index 2f55f451f..aafaf3330 100644
--- a/drivers/bus/vdev/vdev_params.c
+++ b/drivers/bus/vdev/vdev_params.c
@@ -2,11 +2,14 @@
  * Copyright 2018 Gaƫtan Rivet
  */
 
+#include <string.h>
+
 #include <rte_dev.h>
 #include <rte_bus.h>
 #include <rte_bus_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
+#include <rte_devargs.h>
 
 #include "vdev_logs.h"
 #include "vdev_private.h"
@@ -60,3 +63,50 @@ rte_vdev_dev_iterate(const void *start,
 	rte_kvargs_free(kvargs);
 	return dev;
 }
+
+static int
+vdev_driver_kv_parse(const char *key __rte_unused,
+		     const char *value,
+		     void *_devargs)
+{
+	struct rte_devargs *devargs = _devargs;
+	struct rte_vdev_driver *driver;
+
+	/* Verify that the driver matches. */
+	if (rte_vdev_parse(value, &driver))
+		return -1;
+
+	/* Copy the driver name as-is. */
+	snprintf(devargs->name, sizeof(devargs->name), "%s", value);
+	return 0;
+}
+
+int
+rte_vdev_devargs_prepare(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvargs = NULL;
+	char *args;
+	int ret;
+
+	if (devargs->bus_str == NULL)
+		return 0;
+
+	args = strchr(devargs->bus_str, ',');
+	if (args == NULL)
+		return 0;
+	args++;
+
+	kvargs = rte_kvargs_parse(args, vdev_params_keys);
+	if (kvargs == NULL) {
+		VDEV_LOG(ERR, "unable to parse parameter list: %s\n",
+			 devargs->bus_str);
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	ret = rte_kvargs_process(kvargs, "driver",
+				 vdev_driver_kv_parse, devargs);
+
+	rte_kvargs_free(kvargs);
+	return ret;
+}
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff..da57b84dd 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -19,6 +19,12 @@ rte_vdev_dev_iterate(const void *start,
 		     const char *str,
 		     const struct rte_dev_iterator *it);
 
+int
+rte_vdev_parse(const char *name, void *addr);
+
+int
+rte_vdev_devargs_prepare(struct rte_devargs *da);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.18.0