From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <wei.dai@intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id 67B0B37B7
 for <dev@dpdk.org>; Tue, 27 Jun 2017 16:17:34 +0200 (CEST)
Received: from orsmga005.jf.intel.com ([10.7.209.41])
 by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 27 Jun 2017 07:17:33 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.39,399,1493708400"; d="scan'208";a="117957323"
Received: from dpdk6.bj.intel.com ([172.16.182.81])
 by orsmga005.jf.intel.com with ESMTP; 27 Jun 2017 07:17:32 -0700
From: Wei Dai <wei.dai@intel.com>
To: thomas@monjalon.net, wenzhuo.lu@intel.com, konstantin.ananyev@intel.com,
 helin.zhang@intel.com, jingjing.wu@intel.com
Cc: dev@dpdk.org,
	Wei Dai <wei.dai@intel.com>
Date: Tue, 27 Jun 2017 22:07:17 +0800
Message-Id: <1498572438-25125-5-git-send-email-wei.dai@intel.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1498572438-25125-1-git-send-email-wei.dai@intel.com>
References: <1495873329-43303-1-git-send-email-wei.dai@intel.com>
 <1498572438-25125-1-git-send-email-wei.dai@intel.com>
Subject: [dpdk-dev] [PATCH v2 4/5] app/testpmd: add command to test NIC reset
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://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: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 27 Jun 2017 14:17:35 -0000

When a NIC is reset, a message will show it.
And then user can run the command "reset_port port_id"
to process it.

Signed-off-by: Wei Dai <wei.dai@intel.com>
---
 app/test-pmd/cmdline.c | 31 +++++++++++++++++++++++++++++++
 app/test-pmd/config.c  | 13 +++++++++++++
 app/test-pmd/testpmd.h |  1 +
 3 files changed, 45 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index ff8ffd2..90f6bde 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -2588,6 +2588,36 @@ cmdline_parse_inst_t cmd_stop = {
 	},
 };
 
+/* *** reset a port *** */
+struct cmd_reset_port_result {
+	cmdline_fixed_string_t command;
+	uint8_t port_id;
+};
+
+static void cmd_reset_port_parsed(__attribute__((unused)) void *parsed_result,
+			    __attribute__((unused)) struct cmdline *cl,
+			    __attribute__((unused)) void *data)
+{
+	struct cmd_reset_port_result *res = parsed_result;
+	reset_port(res->port_id);
+}
+
+cmdline_parse_token_string_t cmd_reset_port_cmd =
+	TOKEN_STRING_INITIALIZER(struct cmd_reset_port_result, command, "reset_port");
+cmdline_parse_token_num_t cmd_reset_port_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_reset_port_result, port_id, UINT8);
+
+cmdline_parse_inst_t cmd_reset_port = {
+	.f = cmd_reset_port_parsed,
+	.data = NULL,
+	.help_str = "reset_port <port_id>",
+	.tokens = {
+		(void *)&cmd_reset_port_cmd,
+		(void *)&cmd_reset_port_id,
+		NULL,
+	},
+};
+
 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
 
 unsigned int
@@ -13751,6 +13781,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
 	(cmdline_parse_inst_t *)&cmd_stop,
+	(cmdline_parse_inst_t *)&cmd_reset_port,
 	(cmdline_parse_inst_t *)&cmd_mac_addr,
 	(cmdline_parse_inst_t *)&cmd_set_qmap,
 	(cmdline_parse_inst_t *)&cmd_operate_port,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index b0b340e..da3b525 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -3318,3 +3318,16 @@ close_ddp_package_file(uint8_t *buf)
 
 	return -1;
 }
+
+void
+reset_port(portid_t port_id)
+{
+	int diag;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN))
+		return;
+	diag = rte_eth_dev_reset(port_id);
+	if (diag == 0)
+		return;
+	printf("Reset port %d failed. diag=%d\n", port_id, diag);	
+}
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 364502d..956eec5 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -598,6 +598,7 @@ void stop_port(portid_t pid);
 void close_port(portid_t pid);
 void attach_port(char *identifier);
 void detach_port(uint8_t port_id);
+void reset_port(portid_t port_id);
 int all_ports_stopped(void);
 int port_is_started(portid_t port_id);
 void pmd_test_exit(void);
-- 
2.7.4