From: Nithin Dabilpuram <nithind1988@gmail.com>
To: Wenzhuo Lu <wenzhuo.lu@intel.com>,
Jingjing Wu <jingjing.wu@intel.com>,
Bernard Iremonger <bernard.iremonger@intel.com>
Cc: dev@dpdk.org, Nithin Dabilpuram <ndabilpuram@marvell.com>
Subject: [dpdk-dev] [PATCH] app/testpmd: change port detach interface
Date: Mon, 13 May 2019 16:51:12 +0530 [thread overview]
Message-ID: <20190513112112.7069-1-ndabilpuram@marvell.com> (raw)
Message-ID: <20190513112112.k5AejBj8n9ElMX2T1pLNL7quDnu0v5vfzzD2JHqXaUs@z> (raw)
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
next reply other threads:[~2019-05-13 11:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 11:21 Nithin Dabilpuram [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190513112112.7069-1-ndabilpuram@marvell.com \
--to=nithind1988@gmail.com \
--cc=bernard.iremonger@intel.com \
--cc=dev@dpdk.org \
--cc=jingjing.wu@intel.com \
--cc=ndabilpuram@marvell.com \
--cc=wenzhuo.lu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).