From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com
 [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id B6BFBAAC7
 for <dev@dpdk.org>; Wed, 21 Mar 2018 18:16:22 +0100 (CET)
Received: by mail-wr0-f194.google.com with SMTP id s10so5963672wra.13
 for <dev@dpdk.org>; Wed, 21 Mar 2018 10:16:22 -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=KvTs/RBDIUErfPwslOaQUveBvHxTt/GdrWoF5Os/YMI=;
 b=GmUNvc3L7IR6x3/qysilXbIvHHexkpzB/fkdzpjkNtBaFMQvfe5ost2+7CTKFTjj7O
 CrObbswELgFthJJSJwF4lHTrPnz952EBadJ4naKn4zrt0DnwU6DEctMn+weWU6LqMWmL
 di0ExdP4zI1aBInfNgeBHF3FP1xWOYEhwyG5IHwZ98z+hp/gxJIRXg09xcuOcTDLS2PH
 9fmspTfGc702mEb8B+mGg6Dyd15giYgDsQoqX2tALCyG5pv2Qe7dpW9KtBBmYkeWnIua
 ljGR+lQJIViwbVT/StKssKyGBY1DQu6Mv8bHQZaB1/oMMY1w3yQJ/Xjd/TZbJ1+zQ9/F
 5BmQ==
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=KvTs/RBDIUErfPwslOaQUveBvHxTt/GdrWoF5Os/YMI=;
 b=tsXUfWDOtnPX6Kst9v+XmZo22ZF8eqDCqsnOi1krzktrQI3mOBblzQX5HyalBwgW2f
 CiwuHsbAHKxE9D/gOfVnRN5kdlyExyy1e12av6KiyNoy84zd9igFopFTlrpBh1jLeORA
 6HXEEmMfdRUIHmTx7PqPr+Kstj2IFAX3hOtiZTZ1JB0tJgKoWOiRn9uj7TpHYFYkCWLu
 7pZrHFQ+43x0IIoBywlKSnjsEeMRQg57n2EubYCAMzG/KbvoeOs6BdTa5HYZOjM8FlYt
 x/ccAcg7zaKpeLQ8beHoDrbeYexwWmlrap1U4jI0gZ0wEYtPxJtgVMyDyYE3tAOwFKUs
 CuhA==
X-Gm-Message-State: AElRT7FijWlI846LF6p5xP51iALkl+izXlopG2jRV0Te6FXrykh071xW
 xhTEpib/93Mex8wvlYOACIDOViql
X-Google-Smtp-Source: AG47ELvA2xIiRcYX7pJUtZ77cKaHBjDJGBE6QB0b8vGd10X8TTQpd2ITW2HSC20QYhW8WloyeDSKQQ==
X-Received: by 10.223.136.217 with SMTP id g25mr18029016wrg.203.1521652581822; 
 Wed, 21 Mar 2018 10:16:21 -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 l10sm4224101wrf.37.2018.03.21.10.16.20
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 21 Mar 2018 10:16:20 -0700 (PDT)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Date: Wed, 21 Mar 2018 18:15:39 +0100
Message-Id: <6308dd15567ce7a0432c5515c78f1b336f767938.1521652453.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.11.0
In-Reply-To: <cover.1521652453.git.gaetan.rivet@6wind.com>
References: <cover.1521124599.git.gaetan.rivet@6wind.com>
 <cover.1521652453.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1521652453.git.gaetan.rivet@6wind.com>
References: <cover.1521652453.git.gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH v2 18/18] app/testpmd: add show device command
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://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 21 Mar 2018 17:16:22 -0000

A new interactive command is offered:

   show device <device description>

This commands lists all rte_device element matching the device
description. e.g.:

   show device bus=pci
   show device bus=vdev
   show device bus=vdev/class=eth
   show device bus=vdev,driver=net_ring/class=eth
   show device bus=vdev/class=eth,name=net_ring0

These devices may not be otherwise useful, some buses will spawn devices
to keep track of their assets without having a driver to use them.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 app/test-pmd/cmdline.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 40b31ad7e..8ac5fb3ca 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -6701,6 +6701,57 @@ cmdline_parse_inst_t cmd_showportall = {
 	},
 };
 
+/* *** SHOW DEVICE INFO *** */
+struct cmd_showdevice_result {
+	cmdline_fixed_string_t show;
+	cmdline_fixed_string_t device;
+	cmdline_fixed_string_t filter;
+};
+
+static void
+cmd_showdevice_dump_device(const struct rte_device *dev)
+{
+	const struct rte_driver *drv = dev->driver;
+
+	printf("0x%p: %s:%s\n", (const void *)dev, dev->name,
+		drv ? drv->name : "<nil>");
+}
+
+static void cmd_showdevice_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_showdevice_result *res = parsed_result;
+	struct rte_dev_iterator it;
+	const struct rte_device *dev;
+
+	RTE_DEV_FOREACH(dev, res->filter, &it)
+		cmd_showdevice_dump_device(dev);
+}
+
+cmdline_parse_token_string_t cmd_showdevice_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+				show, "show");
+cmdline_parse_token_string_t cmd_showdevice_device =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+				device, "device");
+cmdline_parse_token_string_t cmd_showdevice_filter =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+			filter, NULL);
+
+cmdline_parse_inst_t cmd_showdevice = {
+	.f = cmd_showdevice_parsed,
+	.data = NULL,
+	.help_str = "show device "
+		"<device string>",
+	.tokens = {
+		(void *)&cmd_showdevice_show,
+		(void *)&cmd_showdevice_device,
+		(void *)&cmd_showdevice_filter,
+		NULL,
+	},
+};
+
 /* *** SHOW PORT INFO *** */
 struct cmd_showport_result {
 	cmdline_fixed_string_t show;
@@ -16038,6 +16089,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_help_long,
 	(cmdline_parse_inst_t *)&cmd_quit,
 	(cmdline_parse_inst_t *)&cmd_load_from_file,
+	(cmdline_parse_inst_t *)&cmd_showdevice,
 	(cmdline_parse_inst_t *)&cmd_showport,
 	(cmdline_parse_inst_t *)&cmd_showqueue,
 	(cmdline_parse_inst_t *)&cmd_showportall,
-- 
2.11.0