DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] app/testpmd: change port detach interface
@ 2019-05-13 11:21 Nithin Dabilpuram
  2019-05-13 11:21 ` Nithin Dabilpuram
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Nithin Dabilpuram @ 2019-05-13 11:21 UTC (permalink / raw)
  To: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger; +Cc: dev, Nithin Dabilpuram

With the latest published interface of
rte_eal_hotplug_[add,remove](), and rte_eth_dev_close(),
rte_eth_dev_close() would cleanup all the data structures of
port's eth dev leaving the device common resource intact
if RTE_ETH_DEV_CLOSE_REMOVE is set in dev flags.
So "port detach" (~hotplug remove) should be able to work,
with device identifier like "port attach" as eth_dev could have
been closed already and rte_eth_devices[port_id] reused.

This change alters "port detach" cmdline interface to
work with device identifier like "port attach".

Signed-off-by: Nithin Dabilpuram <ndabilpuram@marvell.com>
---
 app/test-pmd/cmdline.c | 15 ++++++++-------
 app/test-pmd/testpmd.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/testpmd.h |  1 +
 3 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index c1042dd..c11b9d2 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -1456,7 +1456,7 @@ cmdline_parse_inst_t cmd_operate_attach_port = {
 struct cmd_operate_detach_port_result {
 	cmdline_fixed_string_t port;
 	cmdline_fixed_string_t keyword;
-	portid_t port_id;
+	cmdline_fixed_string_t identifier;
 };
 
 static void cmd_operate_detach_port_parsed(void *parsed_result,
@@ -1466,7 +1466,7 @@ static void cmd_operate_detach_port_parsed(void *parsed_result,
 	struct cmd_operate_detach_port_result *res = parsed_result;
 
 	if (!strcmp(res->keyword, "detach"))
-		detach_port_device(res->port_id);
+		detach_port(res->identifier);
 	else
 		printf("Unknown parameter\n");
 }
@@ -1477,18 +1477,19 @@ cmdline_parse_token_string_t cmd_operate_detach_port_port =
 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
 			keyword, "detach");
-cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
-	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
-			port_id, UINT16);
+cmdline_parse_token_string_t cmd_operate_detach_port_identifier =
+	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
+			identifier, NULL);
 
 cmdline_parse_inst_t cmd_operate_detach_port = {
 	.f = cmd_operate_detach_port_parsed,
 	.data = NULL,
-	.help_str = "port detach <port_id>",
+	.help_str = "port detach <identifier>:"
+		"(identifier: pci address or virtual dev name)",
 	.tokens = {
 		(void *)&cmd_operate_detach_port_port,
 		(void *)&cmd_operate_detach_port_keyword,
-		(void *)&cmd_operate_detach_port_port_id,
+		(void *)&cmd_operate_detach_port_identifier,
 		NULL,
 	},
 };
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 6fbfd29..f4ddd94 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2453,6 +2453,51 @@ detach_port_device(portid_t port_id)
 }
 
 void
+detach_port(char *identifier)
+{
+	struct rte_dev_iterator iterator;
+	struct rte_devargs da;
+	portid_t port_id;
+
+	printf("Removing a device...\n");
+
+	memset(&da, 0, sizeof(da));
+	if (rte_devargs_parsef(&da, "%s", identifier)) {
+		printf("cannot parse identifier\n");
+		if (da.args)
+			free(da.args);
+		return;
+	}
+
+	RTE_ETH_FOREACH_MATCHING_DEV(port_id, identifier, &iterator) {
+		if (ports[port_id].port_status != RTE_PORT_CLOSED) {
+			if (ports[port_id].port_status != RTE_PORT_STOPPED) {
+				printf("Port %u not stopped\n", port_id);
+				return;
+			}
+
+			/* sibling ports are forced to be closed */
+			if (ports[port_id].flow_list)
+				port_flow_flush(port_id);
+			ports[port_id].port_status = RTE_PORT_CLOSED;
+			printf("Port %u is now closed\n", port_id);
+		}
+	}
+
+	if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) {
+		TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
+			    da.name, da.bus->name);
+		return;
+	}
+
+	remove_invalid_ports();
+
+	printf("Device %s is detached\n", identifier);
+	printf("Now total ports is %d\n", nb_ports);
+	printf("Done\n");
+}
+
+void
 pmd_test_exit(void)
 {
 	struct rte_device *device;
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 1d9b7a2..3f2e06d 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -788,6 +788,7 @@ void stop_port(portid_t pid);
 void close_port(portid_t pid);
 void reset_port(portid_t pid);
 void attach_port(char *identifier);
+void detach_port(char *identifier);
 void detach_port_device(portid_t port_id);
 int all_ports_stopped(void);
 int port_is_stopped(portid_t port_id);
-- 
2.8.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-07-22 16:08 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 11:21 [dpdk-dev] [PATCH] app/testpmd: change port detach interface Nithin Dabilpuram
2019-05-13 11:21 ` Nithin Dabilpuram
2019-05-14 15:39 ` Thomas Monjalon
2019-05-14 15:39   ` Thomas Monjalon
2019-05-15  6:52   ` Nithin Dabilpuram
2019-05-15  6:52     ` Nithin Dabilpuram
2019-05-15  7:27     ` Thomas Monjalon
2019-05-15  7:27       ` Thomas Monjalon
2019-05-17  8:55       ` Nithin Dabilpuram
2019-05-17  8:59         ` Thomas Monjalon
2019-05-20 12:50           ` Nithin Dabilpuram
2019-05-29  8:16             ` Nithin Dabilpuram
2019-06-25  4:24               ` Nithin Dabilpuram
2019-07-02 15:58               ` Yigit, Ferruh
2019-07-03  5:05                 ` Nithin Dabilpuram
2019-07-10 13:07 ` [dpdk-dev] [PATCH v2] app/testpmd: add device related cmds Nithin Dabilpuram
2019-07-16 18:30   ` Ferruh Yigit
2019-07-17  8:08     ` [dpdk-dev] [EXT] " Nithin Kumar Dabilpuram
2019-07-17 12:30 ` [dpdk-dev] [PATCH v3] " Nithin Dabilpuram
2019-07-17 16:51   ` Ferruh Yigit
2019-07-18  5:27     ` [dpdk-dev] [EXT] " Nithin Kumar Dabilpuram
2019-07-19 19:00       ` Ferruh Yigit
2019-07-22  6:01         ` Hemant Agrawal
2019-07-22  6:15           ` Nithin Kumar Dabilpuram
2019-07-22 16:04             ` Ferruh Yigit
2019-07-17 16:54   ` [dpdk-dev] " Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).