patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 20.11] app/testpmd: fix port status of bonding slave device
@ 2022-06-28  2:14 Huisong Li
  2022-06-28  2:33 ` [PATCH 20.11 V2] " Huisong Li
  0 siblings, 1 reply; 3+ messages in thread
From: Huisong Li @ 2022-06-28  2:14 UTC (permalink / raw)
  To: stable, xuemingl, ktraynor; +Cc: lihuisong, liudongdong3, huangdaode

[ 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 <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Aman Singh <aman.deep.singh@intel.com>
Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
---
 app/test-pmd/cmdline.c |  1 +
 app/test-pmd/testpmd.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/testpmd.h |  3 ++-
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 1741d00ba8..535d199040 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -6328,6 +6328,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 1a7488d8dc..ec8071c3d9 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -60,6 +60,9 @@
 #ifdef RTE_LIB_LATENCYSTATS
 #include <rte_latencystats.h>
 #endif
+#ifdef RTE_NET_BOND
+#include <rte_eth_bond.h>
+#endif
 
 #include "testpmd.h"
 
@@ -2420,6 +2423,38 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 	return ret;
 }
 
+static int
+change_bonding_slave_port_status(portid_t bond_pid, bool is_stop)
+{
+#ifdef RTE_NET_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)
 {
@@ -2603,6 +2638,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)
@@ -2731,6 +2775,17 @@ stop_port(portid_t pid)
 		if (rte_eth_dev_stop(pi) != 0)
 			RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n",
 				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)
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 2d4dc05332..3b4b943c96 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -219,7 +219,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_shared_action *actions_list;
 	/**< Associated shared actions. */
-- 
2.33.0


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

* [PATCH 20.11 V2] app/testpmd: fix port status of bonding slave device
  2022-06-28  2:14 [PATCH 20.11] app/testpmd: fix port status of bonding slave device Huisong Li
@ 2022-06-28  2:33 ` Huisong Li
  2022-06-28 13:35   ` Xueming(Steven) Li
  0 siblings, 1 reply; 3+ messages in thread
From: Huisong Li @ 2022-06-28  2:33 UTC (permalink / raw)
  To: stable, xuemingl, ktraynor; +Cc: lihuisong, liudongdong3, huangdaode

[ 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")

---
v2:
 - clear checkpatch warning

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Aman Singh <aman.deep.singh@intel.com>
Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
---
 app/test-pmd/cmdline.c |  1 +
 app/test-pmd/testpmd.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/testpmd.h |  3 ++-
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 1741d00ba8..535d199040 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -6328,6 +6328,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 1a7488d8dc..7b1d65ea08 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -60,6 +60,9 @@
 #ifdef RTE_LIB_LATENCYSTATS
 #include <rte_latencystats.h>
 #endif
+#ifdef RTE_NET_BOND
+#include <rte_eth_bond.h>
+#endif
 
 #include "testpmd.h"
 
@@ -2420,6 +2423,38 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 	return ret;
 }
 
+static int
+change_bonding_slave_port_status(portid_t bond_pid, bool is_stop)
+{
+#ifdef RTE_NET_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)
 {
@@ -2603,6 +2638,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)
@@ -2731,6 +2775,17 @@ stop_port(portid_t pid)
 		if (rte_eth_dev_stop(pi) != 0)
 			RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n",
 				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)
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 2d4dc05332..3b4b943c96 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -219,7 +219,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_shared_action *actions_list;
 	/**< Associated shared actions. */
-- 
2.33.0


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

* RE: [PATCH 20.11 V2] app/testpmd: fix port status of bonding slave device
  2022-06-28  2:33 ` [PATCH 20.11 V2] " Huisong Li
@ 2022-06-28 13:35   ` Xueming(Steven) Li
  0 siblings, 0 replies; 3+ messages in thread
From: Xueming(Steven) Li @ 2022-06-28 13:35 UTC (permalink / raw)
  To: Huisong Li, stable, ktraynor; +Cc: liudongdong3, huangdaode

Thanks, applied into 20.11 LTS queue.

> -----Original Message-----
> From: Huisong Li <lihuisong@huawei.com>
> Sent: Tuesday, June 28, 2022 10:33 AM
> To: stable@dpdk.org; Xueming(Steven) Li <xuemingl@nvidia.com>; ktraynor@redhat.com
> Cc: lihuisong@huawei.com; liudongdong3@huawei.com; huangdaode@huawei.com
> Subject: [PATCH 20.11 V2] app/testpmd: fix port status of bonding slave device
> 
> [ 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")
> 
> ---
> v2:
>  - clear checkpatch warning
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> Acked-by: Aman Singh <aman.deep.singh@intel.com>
> Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> ---
>  app/test-pmd/cmdline.c |  1 +
>  app/test-pmd/testpmd.c | 55 ++++++++++++++++++++++++++++++++++++++++++
>  app/test-pmd/testpmd.h |  3 ++-
>  3 files changed, 58 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 1741d00ba8..535d199040 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -6328,6 +6328,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 1a7488d8dc..7b1d65ea08 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -60,6 +60,9 @@
>  #ifdef RTE_LIB_LATENCYSTATS
>  #include <rte_latencystats.h>
>  #endif
> +#ifdef RTE_NET_BOND
> +#include <rte_eth_bond.h>
> +#endif
> 
>  #include "testpmd.h"
> 
> @@ -2420,6 +2423,38 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
>  	return ret;
>  }
> 
> +static int
> +change_bonding_slave_port_status(portid_t bond_pid, bool is_stop) {
> +#ifdef RTE_NET_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)
>  {
> @@ -2603,6 +2638,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) @@ -2731,6 +2775,17 @@ stop_port(portid_t pid)
>  		if (rte_eth_dev_stop(pi) != 0)
>  			RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n",
>  				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) diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
> index 2d4dc05332..3b4b943c96 100644
> --- a/app/test-pmd/testpmd.h
> +++ b/app/test-pmd/testpmd.h
> @@ -219,7 +219,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_shared_action *actions_list;
>  	/**< Associated shared actions. */
> --
> 2.33.0


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

end of thread, other threads:[~2022-06-28 13:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28  2:14 [PATCH 20.11] app/testpmd: fix port status of bonding slave device Huisong Li
2022-06-28  2:33 ` [PATCH 20.11 V2] " Huisong Li
2022-06-28 13:35   ` Xueming(Steven) Li

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).