[v4,6/6] net/bonding: add commands for bonding port notification

Message ID 20231018074821.1908906-7-chaoyong.he@corigine.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series Enhance the bond framework to support offload |

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/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Chaoyong He Oct. 18, 2023, 7:48 a.m. UTC
  From: Long Wu <long.wu@corigine.com>

Add some commands to support bonding port notification in
dpdk-testpmd.

1. We can enable the notification by command:
"set bonding notify_member (port_id) (enable|disable)"

2. If member port hardware try to create the bonding port after
notification we can get the status by command:
"get bonding member hardware create (member_port_id) (bonding_port_id)"

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: James Hershaw <james.hershaw@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 .../link_bonding_poll_mode_drv_lib.rst        |  19 +++
 drivers/net/bonding/bonding_testpmd.c         | 128 ++++++++++++++++++
 2 files changed, 147 insertions(+)
  

Patch

diff --git a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
index 60717a3587..9f6443ebd8 100644
--- a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
+++ b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst
@@ -637,3 +637,22 @@  in balance mode with a transmission policy of layer 2+3::
         Members (3): [1 3 4]
         Active Members (3): [1 3 4]
         Primary: [3]
+
+set bonding notify_member
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Set the notify member flag of bonding port::
+
+   testpmd> set bonding notify_member (port_id) (enable|disable)
+
+This command just set the flag of notification.
+If we enable it, bonding PMD will notify member ports when its some
+configurations changed. So member ports can do some private things, maybe hardware
+bonding creation and etc.
+
+get bonding member hardware create
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Get the status of member port hardware creating the bonding port::
+
+   testpmd> get bonding member hardware create (member_port_id) (bonding_port_id)
diff --git a/drivers/net/bonding/bonding_testpmd.c b/drivers/net/bonding/bonding_testpmd.c
index 8fcd6cadd0..da7d9cc58f 100644
--- a/drivers/net/bonding/bonding_testpmd.c
+++ b/drivers/net/bonding/bonding_testpmd.c
@@ -692,6 +692,124 @@  static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
 	}
 };
 
+struct cmd_set_bonding_notify_member_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t bonding;
+	cmdline_fixed_string_t notify_member;
+	uint16_t port_num;
+	cmdline_fixed_string_t mode;
+};
+
+static void
+cmd_set_bonding_notify_member_parsed(void *parsed_result,
+	__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_set_bonding_notify_member_result *res = parsed_result;
+	bool notify_member = false;
+
+	if (strcmp(res->notify_member, "enable") == 0)
+		notify_member = true;
+	else if (strcmp(res->notify_member, "disable") == 0)
+		notify_member = false;
+
+	rte_eth_bond_notify_member_flag_set(res->port_num, notify_member);
+}
+
+static cmdline_parse_token_string_t cmd_set_bonding_notify_member_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_notify_member_result,
+		set, "set");
+static cmdline_parse_token_string_t cmd_set_bonding_notify_member_bonding =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_notify_member_result,
+		bonding, "bonding");
+static cmdline_parse_token_string_t cmd_set_bonding_notify_member =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_notify_member_result,
+		notify_member, "notify_member");
+static cmdline_parse_token_num_t cmd_set_bonding_notify_member_portnum =
+	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_notify_member_result,
+		port_num, RTE_UINT16);
+static cmdline_parse_token_string_t cmd_set_bonding_notify_member_mode_string =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_notify_member_result,
+		mode, "enable#disable");
+
+static cmdline_parse_inst_t cmd_set_bonding_notify_member_ports = {
+	.f = cmd_set_bonding_notify_member_parsed,
+	.data = NULL,
+	.help_str = "set bonding notify_member (port_id) (enable|disable)",
+	.tokens = {
+		(void *)&cmd_set_bonding_notify_member_set,
+		(void *)&cmd_set_bonding_notify_member_bonding,
+		(void *)&cmd_set_bonding_notify_member,
+		(void *)&cmd_set_bonding_notify_member_portnum,
+		(void *)&cmd_set_bonding_notify_member_mode_string,
+		NULL
+	}
+};
+
+struct cmd_get_bonding_member_hw_create_result {
+	cmdline_fixed_string_t get;
+	cmdline_fixed_string_t bonding;
+	cmdline_fixed_string_t member;
+	cmdline_fixed_string_t hardware;
+	cmdline_fixed_string_t create;
+	uint16_t member_port_id;
+	uint16_t bonding_port_id;
+};
+
+static void
+cmd_get_bonding_member_hw_create_parsed(void *parsed_result,
+	__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_get_bonding_member_hw_create_result *res = parsed_result;
+	int ret;
+
+	ret = rte_eth_bond_hw_create_get(res->bonding_port_id, res->member_port_id);
+	if (ret == 0)
+		printf("Member port %u hardware creates bonding port %u successfully\n",
+			res->member_port_id, res->bonding_port_id);
+	else
+		printf("Failed to get status of member port %u hardware creating"
+			" bonding port %u, %d\n",
+			res->member_port_id, res->bonding_port_id, ret);
+}
+
+static cmdline_parse_token_string_t cmd_get_bonding_member_hw_create_get =
+	TOKEN_STRING_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		get, "get");
+static cmdline_parse_token_string_t cmd_get_bonding_member_hw_create_bonding =
+	TOKEN_STRING_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		bonding, "bonding");
+static cmdline_parse_token_string_t cmd_get_bonding_member_hw_create_member =
+	TOKEN_STRING_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		member, "member");
+static cmdline_parse_token_string_t cmd_get_bonding_member_hw_create_hardware =
+	TOKEN_STRING_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		create, "hardware");
+static cmdline_parse_token_string_t cmd_get_bonding_member_hw_create_create =
+	TOKEN_STRING_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		create, "create");
+static cmdline_parse_token_num_t cmd_get_bonding_member_hw_create_memberportid =
+	TOKEN_NUM_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		member_port_id, RTE_UINT16);
+static cmdline_parse_token_num_t cmd_get_bonding_member_hw_create_bondingportid =
+	TOKEN_NUM_INITIALIZER(struct cmd_get_bonding_member_hw_create_result,
+		bonding_port_id, RTE_UINT16);
+
+static cmdline_parse_inst_t cmd_get_member_hw_create_bonding = {
+	.f = cmd_get_bonding_member_hw_create_parsed,
+	.data = NULL,
+	.help_str = "get bonding member hardware create (member_port_id) (bonding_port_id)",
+	.tokens = {
+		(void *)&cmd_get_bonding_member_hw_create_get,
+		(void *)&cmd_get_bonding_member_hw_create_bonding,
+		(void *)&cmd_get_bonding_member_hw_create_member,
+		(void *)&cmd_get_bonding_member_hw_create_hardware,
+		(void *)&cmd_get_bonding_member_hw_create_create,
+		(void *)&cmd_get_bonding_member_hw_create_memberportid,
+		(void *)&cmd_get_bonding_member_hw_create_bondingportid,
+		NULL
+	}
+};
+
 static struct testpmd_driver_commands bonding_cmds = {
 	.commands = {
 	{
@@ -749,6 +867,16 @@  static struct testpmd_driver_commands bonding_cmds = {
 		"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)\n"
 		"	Set Aggregation mode for IEEE802.3AD (mode 4)\n",
 	},
+	{
+		&cmd_set_bonding_notify_member_ports,
+		"set bonding notify_member (port_id) (enable|disable)\n"
+		"	Enable/disable the notify member flag of bonding port\n",
+	},
+	{
+		&cmd_get_member_hw_create_bonding,
+		"get bonding member hardware create (member_port_id) (bonding_port_id)\n"
+		"	Get the status of member port hardware creating the bonding port\n",
+	},
 	{ NULL, NULL },
 	},
 };