From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D2BBFA00C5 for ; Tue, 19 Jul 2022 04:50:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29534427EE; Tue, 19 Jul 2022 04:50:10 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 5D5404069F for ; Tue, 19 Jul 2022 04:50:08 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Ln3B041VlzVg9r; Tue, 19 Jul 2022 10:46:16 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 19 Jul 2022 10:50:02 +0800 Received: from localhost.localdomain (10.28.79.22) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 19 Jul 2022 10:50:01 +0800 From: Huisong Li To: , CC: , , , , Subject: [PATCH 19.11 1/4] app/testpmd: fix port status of bonding slave device Date: Tue, 19 Jul 2022 10:49:16 +0800 Message-ID: <20220719024919.16999-2-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20220719024919.16999-1-lihuisong@huawei.com> References: <20220719024919.16999-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit e46372d7b082706718bb17981ae632e4e4d56414 ] Starting or stopping a bonded port also starts or stops all active slaves under the bonded port. If this port is a bonded device, we need to modify the port status of all slaves. Fixes: 0e545d3047fe ("app/testpmd: check stopping port is not in bonding") Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) Acked-by: Aman Singh Acked-by: Konstantin Ananyev --- app/test-pmd/cmdline.c | 1 + app/test-pmd/testpmd.c | 56 ++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 3 ++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 3a2ba414c8..b7a59203ac 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -6229,6 +6229,7 @@ static void cmd_create_bonded_device_parsed(void *parsed_result, printf("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 2a182eda20..ba4c3dafb7 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -60,6 +60,9 @@ #ifdef RTE_LIBRTE_LATENCY_STATS #include #endif +#ifdef RTE_LIBRTE_PMD_BOND +#include +#endif #include "testpmd.h" @@ -2295,6 +2298,38 @@ setup_hairpin_queues(portid_t pi) return 0; } +static int +change_bonding_slave_port_status(portid_t bond_pid, bool is_stop) +{ +#ifdef RTE_LIBRTE_PMD_BOND + + portid_t slave_pids[RTE_MAX_ETHPORTS]; + struct rte_port *port; + int num_slaves; + portid_t slave_pid; + 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 num_slaves; + } + + for (i = 0; i < num_slaves; i++) { + slave_pid = slave_pids[i]; + port = &ports[slave_pid]; + port->port_status = + is_stop ? RTE_PORT_STOPPED : RTE_PORT_STARTED; + } +#else + RTE_SET_USED(bond_pid); + RTE_SET_USED(is_stop); +#endif + return 0; +} + int start_port(portid_t pid) { @@ -2467,6 +2502,15 @@ start_port(portid_t pid) "stopped\n", pi); continue; } + /* + * Starting a bonded port also starts all slaves under the + * bonded device. So if this port is bond device, we need + * to modify the port status of these slaves. + */ + if (port->bond_flag == 1) { + if (change_bonding_slave_port_status(pi, false) != 0) + continue; + } if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0) @@ -2527,6 +2571,18 @@ stop_port(portid_t pid) rte_eth_dev_stop(pi); + /* + * Stopping a bonded port also stops all slaves under the bonded + * device. So if this port is bond device, we need to modify the + * port status of these slaves. + */ + if (port->bond_flag == 1) { + if (change_bonding_slave_port_status(pi, true) != 0) { + RTE_LOG(ERR, EAL, "Fail to change bonding slave port status %u\n", + pi); + } + } + if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0) printf("Port %d can not be set into stopped\n", pi); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 334bcc28e6..2690dda2e2 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -183,7 +183,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. */ const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1]; const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1]; -- 2.22.0