[2/2] app/testpmd: add support for bonding port's LACP negotiation

Message ID 20230216071514.29418-3-chaoyong.he@corigine.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series enhance bonding PMD to support the LACP negotiation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build fail github build: failed
ci/iol-intel-Functional fail Functional Testing issues
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation fail Compilation issues
ci/iol-testing fail Testing issues
ci/iol-x86_64-unit-testing fail Testing issues
ci/intel-Testing success Testing PASS
ci/iol-x86_64-compile-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS

Commit Message

Chaoyong He Feb. 16, 2023, 7:15 a.m. UTC
  From: Long Wu <long.wu@corigine.com>

If bonding port is mode4 with disabling dedicated queue and there
are no other packets, forward loop will not call port's TX function
and bonding port will not send LACP packets.

Add sending LACP packets periodically in forward loop to avoid
LACP negotiation failed.

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 app/test-pmd/config.c                 | 23 ++++++++++++++
 app/test-pmd/parameters.c             | 10 +++++++
 app/test-pmd/testpmd.c                | 43 ++++++++++++++++++++++++++-
 app/test-pmd/testpmd.h                |  9 ++++++
 doc/guides/testpmd_app_ug/run_app.rst |  4 +++
 5 files changed, 88 insertions(+), 1 deletion(-)
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 41484c3dde..4b7be9cc25 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -53,6 +53,11 @@ 
 #ifdef RTE_LIB_GRO
 #include <rte_gro.h>
 #endif
+#ifdef RTE_NET_BOND
+#include <rte_eth_bond.h>
+#include <rte_eth_bond_8023ad.h>
+#endif
+
 #include <rte_hexdump.h>
 
 #include "testpmd.h"
@@ -4401,6 +4406,12 @@  simple_fwd_config_setup(void)
 		fwd_streams[i]->tx_queue  = 0;
 		fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
 		fwd_streams[i]->retry_enabled = retry_enabled;
+#ifdef RTE_NET_BOND
+		if (rte_eth_bond_8023ad_dedicated_queues_get(fwd_streams[i]->tx_port) == 0)
+			fwd_streams[i]->bond4_send_periodical_lacp = true;
+		else
+			fwd_streams[i]->bond4_send_periodical_lacp = false;
+#endif
 	}
 }
 
@@ -4462,6 +4473,12 @@  rss_fwd_config_setup(void)
 		fs->tx_queue = rxq;
 		fs->peer_addr = fs->tx_port;
 		fs->retry_enabled = retry_enabled;
+#ifdef RTE_NET_BOND
+		if (rte_eth_bond_8023ad_dedicated_queues_get(fs->tx_port) == 0)
+			fs->bond4_send_periodical_lacp = true;
+		else
+			fs->bond4_send_periodical_lacp = false;
+#endif
 		rxp++;
 		if (rxp < nb_fwd_ports)
 			continue;
@@ -4577,6 +4594,12 @@  dcb_fwd_config_setup(void)
 				fs->tx_queue = txq + j % nb_tx_queue;
 				fs->peer_addr = fs->tx_port;
 				fs->retry_enabled = retry_enabled;
+#ifdef RTE_NET_BOND
+				if (rte_eth_bond_8023ad_dedicated_queues_get(fs->tx_port) == 0)
+					fs->bond4_send_periodical_lacp = true;
+				else
+					fs->bond4_send_periodical_lacp = false;
+#endif
 			}
 			fwd_lcores[lc_id]->stream_nb +=
 				rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index e734ad9a02..5952b05b57 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -205,6 +205,9 @@  usage(char* progname)
 	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
+#ifdef RTE_NET_BOND
+	printf("  --bond4-lacp-fwd: enable lacp update in fwd main loop\n");
+#endif
 }
 
 #ifdef RTE_LIB_CMDLINE
@@ -705,6 +708,9 @@  launch_args_parse(int argc, char** argv)
 		{ "rx-mq-mode",                 1, 0, 0 },
 		{ "record-core-cycles",         0, 0, 0 },
 		{ "record-burst-stats",         0, 0, 0 },
+#ifdef RTE_NET_BOND
+		{ "bond4-lacp-fwd",             0, 0, 0 },
+#endif
 		{ PARAM_NUM_PROCS,              1, 0, 0 },
 		{ PARAM_PROC_ID,                1, 0, 0 },
 		{ 0, 0, 0, 0 },
@@ -1462,6 +1468,10 @@  launch_args_parse(int argc, char** argv)
 				num_procs = atoi(optarg);
 			if (!strcmp(lgopts[opt_idx].name, PARAM_PROC_ID))
 				proc_id = atoi(optarg);
+#ifdef RTE_NET_BOND
+			if (!strcmp(lgopts[opt_idx].name, "bond4-lacp-fwd"))
+				bond4_lacp_fwd = 1;
+#endif
 			break;
 		case 'h':
 			usage(argv[0]);
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index a6c5dec4c0..732137d5ce 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -68,6 +68,7 @@ 
 #endif
 #ifdef RTE_NET_BOND
 #include <rte_eth_bond.h>
+#include <rte_eth_bond_8023ad.h>
 #endif
 #ifdef RTE_NET_MLX5
 #include "mlx5_testpmd.h"
@@ -519,6 +520,11 @@  struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
 #endif
 
+#ifdef RTE_NET_BOND
+uint8_t bond4_lacp_fwd;
+#define LACP_UPDATE_PERIOD 10000
+#endif
+
 /*
  * hexadecimal bitmask of RX mq mode can be enabled.
  */
@@ -2252,6 +2258,25 @@  flush_fwd_rx_queues(void)
 	}
 }
 
+#ifdef RTE_NET_BOND
+static inline void
+try_lacp_send_in_fwd(struct fwd_stream **fsm, streamid_t nb_fs)
+{
+	void *qd;
+	streamid_t sm_id;
+	struct rte_eth_fp_ops *p;
+
+	for (sm_id = 0; sm_id < nb_fs; sm_id++) {
+		/* Update bond4 LACP if dedicated queues disabled. */
+		if (fsm[sm_id]->bond4_send_periodical_lacp) {
+			p = &rte_eth_fp_ops[fsm[sm_id]->tx_port];
+			qd = p->txq.data[fsm[sm_id]->tx_queue];
+			rte_eth_bond_8023ad_lacp_send_one(qd);
+		}
+	}
+}
+#endif
+
 static void
 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 {
@@ -2268,6 +2293,11 @@  run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 	cnt_ports = nb_ports;
 	tics_datum = rte_rdtsc();
 	tics_per_1sec = rte_get_timer_hz();
+#endif
+#ifdef RTE_NET_BOND
+	uint64_t before_tsc = rte_rdtsc();
+	const uint64_t bond4_lacp_period = (rte_get_tsc_hz() + US_PER_S - 1) /
+			US_PER_S * LACP_UPDATE_PERIOD;
 #endif
 	fsm = &fwd_streams[fc->stream_idx];
 	nb_fs = fc->stream_nb;
@@ -2300,6 +2330,15 @@  run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 			fc->total_cycles += tsc - prev_tsc;
 			prev_tsc = tsc;
 		}
+#ifdef RTE_NET_BOND
+		if (bond4_lacp_fwd != 0) {
+			uint64_t current_tsc = rte_rdtsc();
+			if (unlikely((current_tsc - before_tsc) > bond4_lacp_period)) {
+				try_lacp_send_in_fwd(fsm, nb_fs);
+				before_tsc = current_tsc;
+			}
+		}
+#endif
 	} while (! fc->stopped);
 }
 
@@ -4462,7 +4501,9 @@  main(int argc, char** argv)
 #ifdef RTE_LIB_LATENCYSTATS
 	latencystats_enabled = 0;
 #endif
-
+#ifdef RTE_NET_BOND
+	bond4_lacp_fwd = 0;
+#endif
 	/* on FreeBSD, mlockall() is disabled by default */
 #ifdef RTE_EXEC_ENV_FREEBSD
 	do_mlockall = 0;
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index b9c77a7a96..5d6673214f 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -175,6 +175,11 @@  struct fwd_stream {
 	unsigned int gro_times;	/**< GRO operation times */
 #endif
 	uint64_t busy_cycles; /**< used with --record-core-cycles */
+	uint64_t     core_cycles; /**< used for RX and TX processing */
+#ifdef RTE_NET_BOND
+	bool bond4_send_periodical_lacp;
+	/**< Send LACP packets periodically in forward loop */
+#endif
 	struct pkt_burst_stats rx_burst_stats;
 	struct pkt_burst_stats tx_burst_stats;
 	struct fwd_lcore *lcore; /**< Lcore being scheduled. */
@@ -582,6 +587,10 @@  extern lcoreid_t bitrate_lcore_id;
 extern uint8_t bitrate_enabled;
 #endif
 
+#ifdef RTE_NET_BOND
+extern uint8_t bond4_lacp_fwd;
+#endif
+
 extern uint32_t max_rx_pkt_len;
 
 /*
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index 3ec3d4f5e6..24aaa9d229 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -538,6 +538,10 @@  The command line options are:
 
     Enable display of RX and TX burst stats.
 
+*   ``--bond4-lacp-fwd``
+
+    Enable LACP packets sending in main forward loop to avoid LACP negotiation failed.
+
 *   ``--hairpin-mode=0xXXXX``
 
     Set the hairpin port configuration with bitmask, only valid when hairpin queues number is set::