Skip to content

Commit b92a9a2

Browse files
James Hershawferruhy
authored andcommitted
app/testpmd: add set dev led on/off command
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 <[email protected]> Reviewed-by: Chaoyong He <[email protected]> Acked-by: Ferruh Yigit <[email protected]>
1 parent 7128789 commit b92a9a2

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

app/test-pmd/cmdline.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ static void cmd_help_long_parsed(void *parsed_result,
674674
"(max_thresh) (prob_inv)]\n"
675675
" Set congestion management configuration\n\n"
676676

677+
"set port (port_id) led (on|off)\n"
678+
" Set a controllable LED associated with a certain"
679+
" port on or off.\n\n"
680+
677681
, list_pkt_forwarding_modes()
678682
);
679683
}
@@ -13512,6 +13516,53 @@ static cmdline_parse_inst_t cmd_config_tx_affinity_map = {
1351213516
},
1351313517
};
1351413518

13519+
/* *** SET THE LED FOR CERTAIN PORT TO ON/OFF *** */
13520+
struct cmd_dev_led_result {
13521+
cmdline_fixed_string_t set;
13522+
cmdline_fixed_string_t port;
13523+
portid_t port_id;
13524+
cmdline_fixed_string_t led;
13525+
cmdline_fixed_string_t state;
13526+
};
13527+
13528+
static void
13529+
cmd_set_dev_led_parsed(void *parsed_result,
13530+
__rte_unused struct cmdline *cl,
13531+
__rte_unused void *data)
13532+
{
13533+
struct cmd_dev_led_result *res = parsed_result;
13534+
13535+
if (strcmp(res->state, "on") == 0)
13536+
set_dev_led(res->port_id, true);
13537+
else
13538+
set_dev_led(res->port_id, false);
13539+
}
13540+
13541+
static cmdline_parse_token_string_t cmd_dev_led_set =
13542+
TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, set, "set");
13543+
static cmdline_parse_token_string_t cmd_dev_led_port =
13544+
TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, port, "port");
13545+
static cmdline_parse_token_num_t cmd_dev_led_port_id =
13546+
TOKEN_NUM_INITIALIZER(struct cmd_dev_led_result, port_id, RTE_UINT16);
13547+
static cmdline_parse_token_string_t cmd_dev_led =
13548+
TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, led, "led");
13549+
static cmdline_parse_token_string_t cmd_dev_state =
13550+
TOKEN_STRING_INITIALIZER(struct cmd_dev_led_result, state, "on#off");
13551+
13552+
static cmdline_parse_inst_t cmd_set_dev_led = {
13553+
.f = cmd_set_dev_led_parsed,
13554+
.data = NULL,
13555+
.help_str = "set port <port_id> led <on/off>",
13556+
.tokens = {
13557+
(void *)&cmd_dev_led_set,
13558+
(void *)&cmd_dev_led_port,
13559+
(void *)&cmd_dev_led_port_id,
13560+
(void *)&cmd_dev_led,
13561+
(void *)&cmd_dev_state,
13562+
NULL,
13563+
},
13564+
};
13565+
1351513566
/* ******************************************************************************** */
1351613567

1351713568
/* list of instructions */
@@ -13756,6 +13807,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
1375613807
&cmd_show_port_cman_config,
1375713808
&cmd_set_port_cman_config,
1375813809
&cmd_config_tx_affinity_map,
13810+
&cmd_set_dev_led,
1375913811
NULL,
1376013812
};
1376113813

app/test-pmd/config.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,6 +5371,26 @@ set_fwd_eth_peer(portid_t port_id, char *peer_addr)
53715371
peer_eth_addrs[port_id] = new_peer_addr;
53725372
}
53735373

5374+
void
5375+
set_dev_led(portid_t port_id, bool active)
5376+
{
5377+
int ret;
5378+
5379+
if (!rte_eth_dev_is_valid_port(port_id)) {
5380+
fprintf(stderr, "Error: Invalid port number %u\n", port_id);
5381+
return;
5382+
}
5383+
5384+
if (active)
5385+
ret = rte_eth_led_on(port_id);
5386+
else
5387+
ret = rte_eth_led_off(port_id);
5388+
5389+
if (ret < 0)
5390+
fprintf(stderr, "Error: Unable to change LED state for port %u: %s\n",
5391+
port_id, rte_strerror(-ret));
5392+
}
5393+
53745394
int
53755395
set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
53765396
{

app/test-pmd/testpmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ int init_fwd_streams(void);
944944
void update_fwd_ports(portid_t new_pid);
945945

946946
void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
947+
void set_dev_led(portid_t port_id, bool active);
947948

948949
void port_mtu_set(portid_t port_id, uint16_t mtu);
949950
int port_action_handle_create(portid_t port_id, uint32_t id, bool indirect_list,

doc/guides/testpmd_app_ug/testpmd_funcs.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,13 @@ during the flow rule creation::
18551855

18561856
Otherwise the default index ``0`` is used.
18571857

1858+
set port led
1859+
~~~~~~~~~~~~
1860+
1861+
Set a controllable LED associated with a certain port on or off::
1862+
1863+
testpmd> set port (port_id) led (on|off)
1864+
18581865
Port Functions
18591866
--------------
18601867

0 commit comments

Comments
 (0)