DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com,
	James Hershaw <james.hershaw@corigine.com>,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH v5 2/2] app/testpmd: add set dev led on/off command
Date: Thu, 10 Oct 2024 14:42:06 +0800	[thread overview]
Message-ID: <20241010064206.3527959-3-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20241010064206.3527959-1-chaoyong.he@corigine.com>

From: James Hershaw <james.hershaw@corigine.com>

Add command to change the state of a controllable LED on an ethdev port
to on/off. This is for the purpose of identifying which physical port is
associated with an ethdev.

Usage:
  testpmd> set port <port-id> led <on/off>

Signed-off-by: James Hershaw <james.hershaw@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 app/test-pmd/cmdline.c                      | 52 +++++++++++++++++++++
 app/test-pmd/config.c                       | 20 ++++++++
 app/test-pmd/testpmd.h                      |  1 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  7 +++
 4 files changed, 80 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index c917c4e83b..61c46d6394 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -674,6 +674,10 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"(max_thresh) (prob_inv)]\n"
 			"    Set congestion management configuration\n\n"
 
+			"set port (port_id) led (on|off)\n"
+			"    Set a controllable LED associated with a certain"
+			" port on or off.\n\n"
+
 			, list_pkt_forwarding_modes()
 		);
 	}
@@ -13512,6 +13516,53 @@ static cmdline_parse_inst_t cmd_config_tx_affinity_map = {
 	},
 };
 
+/* *** SET THE LED FOR CERTAIN PORT TO ON/OFF *** */
+struct cmd_dev_led_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t port;
+	portid_t port_id;
+	cmdline_fixed_string_t led;
+	cmdline_fixed_string_t state;
+};
+
+static void
+cmd_set_dev_led_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_dev_led_result *res = parsed_result;
+
+	if (strcmp(res->state, "on") == 0)
+		set_dev_led(res->port_id, true);
+	else
+		set_dev_led(res->port_id, false);
+}
+
+static cmdline_parse_token_string_t cmd_dev_led_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, set, "set");
+static cmdline_parse_token_string_t cmd_dev_led_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, port, "port");
+static cmdline_parse_token_num_t cmd_dev_led_port_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_dev_led_result, port_id, RTE_UINT16);
+static cmdline_parse_token_string_t cmd_dev_led =
+	TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, led, "led");
+static cmdline_parse_token_string_t cmd_dev_state =
+	TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, state, "on#off");
+
+static cmdline_parse_inst_t cmd_set_dev_led = {
+	.f = cmd_set_dev_led_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> led <on/off>",
+	.tokens = {
+		(void *)&cmd_dev_led_set,
+		(void *)&cmd_dev_led_port,
+		(void *)&cmd_dev_led_port_id,
+		(void *)&cmd_dev_led,
+		(void *)&cmd_dev_state,
+		NULL,
+	},
+};
+
 /* ******************************************************************************** */
 
 /* list of instructions */
@@ -13755,6 +13806,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_show_port_cman_config,
 	&cmd_set_port_cman_config,
 	&cmd_config_tx_affinity_map,
+	&cmd_set_dev_led,
 	NULL,
 };
 
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 37f074a69b..88770b4dfc 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -5371,6 +5371,26 @@ set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
+void
+set_dev_led(portid_t port_id, bool active)
+{
+	int ret;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		fprintf(stderr, "Error: Invalid port number %u\n", port_id);
+		return;
+	}
+
+	if (active)
+		ret = rte_eth_led_on(port_id);
+	else
+		ret = rte_eth_led_off(port_id);
+
+	if (ret < 0)
+		fprintf(stderr, "Error: Unable to change LED state for port %u: %s\n",
+			port_id, rte_strerror(-ret));
+}
+
 int
 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
 {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 56ab7ef1db..84517b0be7 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -944,6 +944,7 @@ int init_fwd_streams(void);
 void update_fwd_ports(portid_t new_pid);
 
 void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
+void set_dev_led(portid_t port_id, bool active);
 
 void port_mtu_set(portid_t port_id, uint16_t mtu);
 int port_action_handle_create(portid_t port_id, uint32_t id, bool indirect_list,
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index eb19e747b5..0228a07701 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1855,6 +1855,13 @@ during the flow rule creation::
 
 Otherwise the default index ``0`` is used.
 
+set port led
+~~~~~~~~~~~~
+
+Set a controllable LED associated with a certain port on or off::
+
+   testpmd> set port (port_id) led (on|off)
+
 Port Functions
 --------------
 
-- 
2.39.1


  parent reply	other threads:[~2024-10-10  6:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12  6:10 [PATCH 0/2] add two commands for testpmd application Chaoyong He
2024-09-12  6:10 ` [PATCH 1/2] app/testpmd: add support for setting device EEPROM Chaoyong He
2024-09-12  6:10 ` [PATCH 2/2] app/testpmd: add set dev led on/off command Chaoyong He
2024-09-12  6:54 ` [PATCH v2 0/2] add two commands for testpmd application Chaoyong He
2024-09-12  6:54   ` [PATCH v2 1/2] app/testpmd: add support for setting device EEPROM Chaoyong He
2024-09-12  9:05     ` fengchengwen
2024-09-13 10:07       ` Chaoyong He
2024-09-12  6:54   ` [PATCH v2 2/2] app/testpmd: add set dev led on/off command Chaoyong He
2024-09-12  8:38     ` fengchengwen
2024-09-13 10:06       ` Chaoyong He
2024-09-14  1:49   ` [PATCH v3 0/2] add two commands for testpmd application Chaoyong He
2024-09-14  1:49     ` [PATCH v3 1/2] app/testpmd: add support for setting device EEPROM Chaoyong He
2024-09-14  7:50       ` fengchengwen
2024-09-14  1:49     ` [PATCH v3 2/2] app/testpmd: add set dev led on/off command Chaoyong He
2024-09-14  7:27       ` fengchengwen
2024-09-18  2:38     ` [PATCH v4 0/2] add two commands for testpmd application Chaoyong He
2024-09-18  2:38       ` [PATCH v4 1/2] app/testpmd: add support for setting device EEPROM Chaoyong He
2024-09-29 22:45         ` Ferruh Yigit
2024-10-10  5:55           ` Chaoyong He
2024-09-18  2:38       ` [PATCH v4 2/2] app/testpmd: add set dev led on/off command Chaoyong He
2024-09-29 22:51         ` Ferruh Yigit
2024-10-10  5:52           ` Chaoyong He
2024-10-10  6:42       ` [PATCH v5 0/2] add two commands for testpmd application Chaoyong He
2024-10-10  6:42         ` [PATCH v5 1/2] app/testpmd: add support for setting device EEPROM Chaoyong He
2024-10-10  6:42         ` Chaoyong He [this message]
2024-10-12  1:28         ` [PATCH v5 0/2] add two commands for testpmd application Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241010064206.3527959-3-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=james.hershaw@corigine.com \
    --cc=oss-drivers@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).