From patchwork Mon Oct 25 06:39:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 102736 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B1983A0C47; Mon, 25 Oct 2021 08:41:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 222BB41125; Mon, 25 Oct 2021 08:41:24 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 2D339410DB for ; Mon, 25 Oct 2021 08:41:20 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Hd4x22wXfzbhJs; Mon, 25 Oct 2021 14:36:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Mon, 25 Oct 2021 14:41:15 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Mon, 25 Oct 2021 14:39:20 +0800 Message-ID: <20211025063922.34066-2-humin29@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025063922.34066-1-humin29@huawei.com> References: <20211025063922.34066-1-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/3] app/testpmd: fix port status of active slave device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Huisong Li Stopping a bond device also stops all active slaves under the bond device. If this port is bond device, we need to modify the port status of all slaves from RTE_PORT_STARTED to RTE_PORT_STOPPED. Fixes: 0e545d3047fe ("app/testpmd: check stopping port is not in bonding") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) Acked-by: Aman Singh --- app/test-pmd/cmdline.c | 1 + app/test-pmd/testpmd.c | 49 +++++++++++++++++++++++++++++++++++++++--- app/test-pmd/testpmd.h | 3 ++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 722f4fb9d9..5bfb4b509b 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -6639,6 +6639,7 @@ static void cmd_create_bonded_device_parsed(void *parsed_result, "Failed to enable promiscuous mode for port %u: %s - ignore\n", port_id, rte_strerror(-ret)); + ports[port_id].bond_flag = 1; ports[port_id].need_setup = 0; ports[port_id].port_status = RTE_PORT_STOPPED; } diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index af0e79fe6d..d6b9ebc4dd 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -65,6 +65,9 @@ #ifdef RTE_EXEC_ENV_WINDOWS #include #endif +#ifdef RTE_NET_BOND +#include +#endif #include "testpmd.h" @@ -2986,6 +2989,35 @@ start_port(portid_t pid) return 0; } +#ifdef RTE_NET_BOND +static void +change_bonding_active_slave_port_status(portid_t bond_pid) +{ + portid_t slave_pids[RTE_MAX_ETHPORTS]; + struct rte_port *port; + int num_active_slaves; + portid_t slave_pid; + int i; + + num_active_slaves = rte_eth_bond_active_slaves_get(bond_pid, slave_pids, + RTE_MAX_ETHPORTS); + if (num_active_slaves < 0) { + fprintf(stderr, "Failed to get slave list for port = %u\n", + bond_pid); + return; + } + + for (i = 0; i < num_active_slaves; i++) { + slave_pid = slave_pids[i]; + port = &ports[slave_pid]; + if (rte_atomic16_cmpset(&(port->port_status), + RTE_PORT_STARTED, RTE_PORT_STOPPED) == 0) + fprintf(stderr, "Port %u can not be set into stopped\n", + slave_pid); + } +} +#endif + void stop_port(portid_t pid) { @@ -3042,9 +3074,20 @@ stop_port(portid_t pid) if (port->flow_list) port_flow_flush(pi); - if (eth_dev_stop_mp(pi) != 0) - RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n", - pi); + if (is_proc_primary()) { +#ifdef RTE_NET_BOND + /* + * Stopping a bond device also stops all active slaves + * under the bond device. If this port is bond device, + * we need to modify the port status of all slaves. + */ + if (port->bond_flag == 1) + change_bonding_active_slave_port_status(pi); +#endif + if (rte_eth_dev_stop(pi) != 0) + RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n", + pi); + } if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0) diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e3995d24ab..ad3b4f875c 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -237,7 +237,8 @@ struct rte_port { struct rte_eth_txconf tx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx configuration */ struct rte_ether_addr *mc_addr_pool; /**< pool of multicast addrs */ uint32_t mc_addr_nb; /**< nb. of addr. in mc_addr_pool */ - uint8_t slave_flag; /**< bonding slave port */ + uint8_t slave_flag : 1, /**< bonding slave port */ + bond_flag : 1; /**< port is bond device */ struct port_flow *flow_list; /**< Associated flows. */ struct port_indirect_action *actions_list; /**< Associated indirect actions. */ From patchwork Mon Oct 25 06:39:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 102735 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41962A0C47; Mon, 25 Oct 2021 08:41:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12D9F410FF; Mon, 25 Oct 2021 08:41:23 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 079554003E for ; Mon, 25 Oct 2021 08:41:19 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Hd4x24F52zQj7D; Mon, 25 Oct 2021 14:36:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Mon, 25 Oct 2021 14:41:15 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Mon, 25 Oct 2021 14:39:21 +0800 Message-ID: <20211025063922.34066-3-humin29@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025063922.34066-1-humin29@huawei.com> References: <20211025063922.34066-1-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 2/3] app/testpmd: fix slave device isn't released X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Huisong Li Currently, some eth devices are added to bond device, these devices are not released when the quit command is executed in testpmd. This patch adds the release operation for all active slaves under a bond device. Fixes: 0e545d3047fe ("app/testpmd: check stopping port is not in bonding") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) --- app/test-pmd/cmdline.c | 1 + app/test-pmd/testpmd.c | 67 ++++++++++++++++++++++++++++++++++++------ app/test-pmd/testpmd.h | 1 + 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 5bfb4b509b..98236a8be3 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -8743,6 +8743,7 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result, __rte_unused void *data) { cmdline_quit(cl); + cl_quit = 1; } cmdline_parse_token_string_t cmd_quit_quit = diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index d6b9ebc4dd..fea9744bd6 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -221,6 +221,7 @@ unsigned int xstats_display_num; /**< Size of extended statistics to show */ * option. Set flag to exit stats period loop after received SIGINT/SIGTERM. */ uint8_t f_quit; +uint8_t cl_quit; /* Quit testpmd from cmdline. */ /* * Max Rx frame size, set by '--max-pkt-len' parameter. @@ -613,15 +614,6 @@ eth_dev_start_mp(uint16_t port_id) return 0; } -static int -eth_dev_stop_mp(uint16_t port_id) -{ - if (is_proc_primary()) - return rte_eth_dev_stop(port_id); - - return 0; -} - static void mempool_free_mp(struct rte_mempool *mp) { @@ -3123,6 +3115,55 @@ remove_invalid_ports(void) nb_cfg_ports = nb_fwd_ports; } +#ifdef RTE_NET_BOND +static void +handle_bonding_slave_device(portid_t bond_pid) +{ + portid_t slave_pids[RTE_MAX_ETHPORTS]; + struct rte_port *port; + portid_t slave_pid; + int num_slaves; + int i; + + num_slaves = rte_eth_bond_slaves_get(bond_pid, slave_pids, + RTE_MAX_ETHPORTS); + if (num_slaves < 0) { + fprintf(stderr, "Failed to get slave list for port = %u\n", + bond_pid); + return; + } + + for (i = 0; i < num_slaves; i++) { + slave_pid = slave_pids[i]; + /* Before removing a slave device, stop the slave device. */ + if (port_is_started(slave_pid) == 1) { + if (rte_eth_dev_stop(slave_pid) != 0) + fprintf(stderr, "rte_eth_dev_stop failed for port %u\n", + slave_pid); + + port = &ports[slave_pid]; + if (rte_atomic16_cmpset(&(port->port_status), + RTE_PORT_STARTED, RTE_PORT_STOPPED) == 0) + fprintf(stderr, "Port %u can not be set into stopped\n", + slave_pid); + } + + /* + * Remove the slave from a bonded device in case of failing to + * close bond device. + */ + if (rte_eth_bond_slave_remove(bond_pid, slave_pid) != 0) + fprintf(stderr, "Failed to remove slave %u from master port = %u\n", + slave_pid, bond_pid); + clear_port_slave_flag(slave_pid); + + /* Close slave device when testpmd quit or is killed. */ + if (cl_quit == 1 || f_quit == 1) + rte_eth_dev_close(slave_pid); + } +} +#endif + void close_port(portid_t pid) { @@ -3161,6 +3202,14 @@ close_port(portid_t pid) if (is_proc_primary()) { port_flow_flush(pi); +#ifdef RTE_NET_BOND + /* + * If this port is bond device, all slaves under the + * device need to be removed or closed. + */ + if (port->bond_flag == 1) + handle_bonding_slave_device(pi); +#endif port_flex_item_flush(pi); rte_eth_dev_close(pi); } diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ad3b4f875c..216fc41432 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -27,6 +27,7 @@ #define RTE_PORT_STARTED (uint16_t)1 #define RTE_PORT_CLOSED (uint16_t)2 #define RTE_PORT_HANDLING (uint16_t)3 +extern uint8_t cl_quit; /* * It is used to allocate the memory for hash key. From patchwork Mon Oct 25 06:39:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 102738 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9CFA9A0C47; Mon, 25 Oct 2021 08:41:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8BAF0410DA; Mon, 25 Oct 2021 08:41:57 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 59BA94003E for ; Mon, 25 Oct 2021 08:41:54 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Hd50C0kg8zZcNw; Mon, 25 Oct 2021 14:39:23 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Mon, 25 Oct 2021 14:41:15 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Mon, 25 Oct 2021 14:39:22 +0800 Message-ID: <20211025063922.34066-4-humin29@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025063922.34066-1-humin29@huawei.com> References: <20211025063922.34066-1-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 3/3] app/testpmd: remove unused header file X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Huisong Li This patch removes unused "rte_eth_bond.h" header file. Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) Reviewed-by: Ferruh Yigit --- app/test-pmd/parameters.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index ab8e8f7e69..1dc83200a8 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -38,9 +38,6 @@ #include #include #include -#ifdef RTE_NET_BOND -#include -#endif #include #include "testpmd.h"