From patchwork Mon May 13 11:21:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nithin Dabilpuram X-Patchwork-Id: 53388 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 817724CA6; Mon, 13 May 2019 13:21:39 +0200 (CEST) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by dpdk.org (Postfix) with ESMTP id 9A1474C9D for ; Mon, 13 May 2019 13:21:37 +0200 (CEST) Received: by mail-pl1-f194.google.com with SMTP id n8so6328490plp.10 for ; Mon, 13 May 2019 04:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZaS3z1PmtUGml2ETljcbpHb0LaAF0ZW5z2h67lZr39g=; b=O9l8xCgW6YSo1CaQMXoTLkTex53IXvS48sPMs61+t0tzqIR7z1QJ5YDmCtJoQBOPSA yl+74ATna/GcFq2RW+p4OOTpaDeLk5AUk2JrOMdGzVkKD+IRVsMUycmx4BAqG/XmTq0F CGl8dw3chZyJSmVrLDncMrxITD6HRg3Y+vVpthONhxqH6rs13UQUu8V2LapzoVnb7a// oYzdXts/e2rf3zRiL3yMNwUe+YWA/inM2dAnZpfYKBFSwL+PQkyhBp9kTpdHcXw5qZUj +Eu4sw84YX6vvak1swG5uU9bheiFOtMPGhDDJLiHrqBsri3Hmb44kXj0ttZ+UwcfF29Q iJPw== 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; bh=ZaS3z1PmtUGml2ETljcbpHb0LaAF0ZW5z2h67lZr39g=; b=YLzNfKWHaNjI630o7HKa/KjKI10XHhmEkW5exhsuPr4RwbQbRt2sx2S3wCGR+IGsGS DXTupaPL3P32wx7gJtLfQLPMaMa/DCQsGWl7NUQjqLAtIzhMeoOQM/foUFqAAVPLCjc7 vpjnrjCovA4CAk6W1zulw88BwPQg9pQP4et7BX+R1aT4nE7cgJTaYT80CwkoHY3VodXq w4hrPDoJiLtjpdlaagIqSigSv98yKksetVF1CfrpSbIe5ZEuhVenrgr6zmtIDTNJQuiV qkcEogkQNrcIlJ+MdMizoqRdkgQiChO20koL/7VG0D/32Y+6hQDtWvDw3kQnHTPkJq7a mS2w== X-Gm-Message-State: APjAAAXbvHZcPaxKyigKr1E2d7DFGeiyiUx6mkJbGSkL5kiT1jYUAOnv C9JNV57w1pKcw9mK48tjw08= X-Google-Smtp-Source: APXvYqzsVHVHX9w8FBBw2AyzU1Ti7Lay4hbn8ZOSZ7C/HuWUV7BhzezobyncSS5k1YEpKmKBWzBTRg== X-Received: by 2002:a17:902:b098:: with SMTP id p24mr29759809plr.38.1557746496698; Mon, 13 May 2019 04:21:36 -0700 (PDT) Received: from hyd1434t5810.caveonetworks.com ([115.113.156.2]) by smtp.gmail.com with ESMTPSA id k64sm43035434pfc.97.2019.05.13.04.21.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 May 2019 04:21:36 -0700 (PDT) From: Nithin Dabilpuram X-Google-Original-From: Nithin Dabilpuram To: Wenzhuo Lu , Jingjing Wu , Bernard Iremonger Cc: dev@dpdk.org, Nithin Dabilpuram Date: Mon, 13 May 2019 16:51:12 +0530 Message-Id: <20190513112112.7069-1-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 Subject: [dpdk-dev] [PATCH] app/testpmd: change port detach interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 ", + .help_str = "port detach :" + "(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);