From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jingche2@shecgisg003.sh.intel.com>
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id AC10D68C1
 for <dev@dpdk.org>; Thu, 14 Aug 2014 09:32:11 +0200 (CEST)
Received: from orsmga001.jf.intel.com ([10.7.209.18])
 by orsmga101.jf.intel.com with ESMTP; 14 Aug 2014 00:35:14 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.01,861,1400050800"; d="scan'208";a="558402548"
Received: from shvmail01.sh.intel.com ([10.239.29.42])
 by orsmga001.jf.intel.com with ESMTP; 14 Aug 2014 00:35:13 -0700
Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com
 [10.239.29.90])
 by shvmail01.sh.intel.com with ESMTP id s7E7ZBhm028899;
 Thu, 14 Aug 2014 15:35:11 +0800
Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1])
 by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id
 s7E7Z8D6031037; Thu, 14 Aug 2014 15:35:10 +0800
Received: (from jingche2@localhost)
 by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id s7E7Z8XE031033;
 Thu, 14 Aug 2014 15:35:08 +0800
From: "Chen Jing D(Mark)" <jing.d.chen@intel.com>
To: dev@dpdk.org
Date: Thu, 14 Aug 2014 15:35:00 +0800
Message-Id: <1408001703-30919-2-git-send-email-jing.d.chen@intel.com>
X-Mailer: git-send-email 1.7.0.7
In-Reply-To: <1408001703-30919-1-git-send-email-jing.d.chen@intel.com>
References: <1408001703-30919-1-git-send-email-jing.d.chen@intel.com>
Subject: [dpdk-dev] [PATCH 1/4] testpmd: add command to start/stop specfic
	queue
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <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: Thu, 14 Aug 2014 07:32:12 -0000

From: "Chen Jing D(Mark)" <jing.d.chen@intel.com>

rte_ether library provide function pointer to start/stop specific
RX/TX queue, NIC driver also implemented functions. This change
adds command in testpmd to start/stop specific RX/TX queue.

Signed-off-by: Chen Jing D(Mark) <jing.d.chen@intel.com>
Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Reviewed-by: Changchun Ouyang <changchun.ouyang@intel.com>
Reviewed-by: Huawei Xie <huawei.xie@intel.com>
---
 app/test-pmd/cmdline.c |   95 ++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c  |    6 ++--
 app/test-pmd/testpmd.c |   12 ++++++
 app/test-pmd/testpmd.h |    4 ++
 4 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 345be11..ddf5def 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -565,6 +565,10 @@ static void cmd_help_long_parsed(void *parsed_result,
 			" tx rs bit threshold.\n\n"
 			"port config mtu X value\n"
 			"    Set the MTU of port X to a given value\n\n"
+
+			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
+			"    Start/stop a rx/tx queue of port X. Only take effect"
+			" when port X is started\n"
 		);
 	}
 
@@ -1425,6 +1429,96 @@ cmdline_parse_inst_t cmd_config_rss_hash_key = {
 	},
 };
 
+/* *** configure port rxq/txq start/stop *** */
+struct cmd_config_rxtx_queue {
+	cmdline_fixed_string_t port;
+	uint8_t portid;
+	cmdline_fixed_string_t rxtxq;
+	uint16_t qid;
+	cmdline_fixed_string_t opname;
+};
+
+static void
+cmd_config_rxtx_queue_parsed(void *parsed_result,
+			__attribute__((unused)) struct cmdline *cl,
+			__attribute__((unused)) void *data)
+{
+	struct cmd_config_rxtx_queue *res = parsed_result;
+	uint8_t isrx;
+	uint8_t isstart;
+
+	if (test_done == 0) {
+		printf("Please stop forwarding first\n");
+		return;
+	}
+
+	if (port_id_is_invalid(res->portid))
+		return;
+
+	if (port_is_started(res->portid) != 1) {
+		printf("Please start port %u first\n", res->portid);
+		return;
+	}
+
+	if (!strcmp(res->rxtxq, "rxq"))
+		isrx = 1;
+	else if (!strcmp(res->rxtxq, "txq"))
+		isrx = 0;
+	else {
+		printf("Unknown parameter\n");
+		return;
+	}
+
+	if (isrx && rx_queue_id_is_invalid(res->qid))
+		return;
+	else if (!isrx && tx_queue_id_is_invalid(res->qid))
+		return;
+
+	if (!strcmp(res->opname, "start"))
+		isstart = 1;
+	else if (!strcmp(res->opname, "stop"))
+		isstart = 0;
+	else {
+		printf("Unknown parameter\n");
+		return;
+	}
+
+	if (isstart && isrx)
+		rte_eth_dev_rx_queue_start(res->portid, res->qid);
+	else if (!isstart && isrx)
+		rte_eth_dev_rx_queue_stop(res->portid, res->qid);
+	else if (isstart && !isrx)
+		rte_eth_dev_tx_queue_start(res->portid, res->qid);
+	else
+		rte_eth_dev_tx_queue_stop(res->portid, res->qid);
+}
+
+cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
+cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
+cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
+cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
+cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
+						"start#stop");
+
+cmdline_parse_inst_t cmd_config_rxtx_queue = {
+	.f = cmd_config_rxtx_queue_parsed,
+	.data = NULL,
+	.help_str = "port X rxq|txq ID start|stop",
+	.tokens = {
+		(void *)&cmd_config_speed_all_port,
+		(void *)&cmd_config_rxtx_queue_portid,
+		(void *)&cmd_config_rxtx_queue_rxtxq,
+		(void *)&cmd_config_rxtx_queue_qid,
+		(void *)&cmd_config_rxtx_queue_opname,
+		NULL,
+	},
+};
+
 /* *** Configure RSS RETA *** */
 struct cmd_config_rss_reta {
 	cmdline_fixed_string_t port;
@@ -7393,6 +7487,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
 	(cmdline_parse_inst_t *)&cmd_config_rss,
+	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
 	(cmdline_parse_inst_t *)&cmd_showport_reta,
 	(cmdline_parse_inst_t *)&cmd_config_burst,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index c72f6ee..606e34a 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -311,7 +311,7 @@ port_infos_display(portid_t port_id)
 	}
 }
 
-static int
+int
 port_id_is_invalid(portid_t port_id)
 {
 	if (port_id < nb_ports)
@@ -521,7 +521,7 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
 /*
  * RX/TX ring descriptors display functions.
  */
-static int
+int
 rx_queue_id_is_invalid(queueid_t rxq_id)
 {
 	if (rxq_id < nb_rxq)
@@ -530,7 +530,7 @@ rx_queue_id_is_invalid(queueid_t rxq_id)
 	return 1;
 }
 
-static int
+int
 tx_queue_id_is_invalid(queueid_t txq_id)
 {
 	if (txq_id < nb_txq)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e8a4b45..a112559 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -1513,6 +1513,18 @@ all_ports_stopped(void)
 	return 1;
 }
 
+int
+port_is_started(portid_t port_id)
+{
+	if (port_id_is_invalid(port_id))
+		return -1;
+
+	if (ports[port_id].port_status != RTE_PORT_STARTED)
+		return 0;
+
+	return 1;
+}
+
 void
 pmd_test_exit(void)
 {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ac86bfe..b8322a2 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -511,6 +511,7 @@ int start_port(portid_t pid);
 void stop_port(portid_t pid);
 void close_port(portid_t pid);
 int all_ports_stopped(void);
+int port_is_started(portid_t port_id);
 void pmd_test_exit(void);
 
 void fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
@@ -547,6 +548,9 @@ void get_ethertype_filter(uint8_t port_id, uint16_t index);
 void get_2tuple_filter(uint8_t port_id, uint16_t index);
 void get_5tuple_filter(uint8_t port_id, uint16_t index);
 void get_flex_filter(uint8_t port_id, uint16_t index);
+int port_id_is_invalid(portid_t port_id);
+int rx_queue_id_is_invalid(queueid_t rxq_id);
+int tx_queue_id_is_invalid(queueid_t txq_id);
 
 /*
  * Work-around of a compilation error with ICC on invocations of the
-- 
1.7.7.6