f-stack/dpdk/examples/multi_process/hotplug_mp/commands.c

94 lines
2.1 KiB
C
Raw Normal View History

2019-06-25 11:12:58 +00:00
/* SPDX-License-Identifier: BSD-3-Clause
2025-01-10 11:50:43 +00:00
* Copyright(c) 2018-2023 Intel Corporation.
2019-06-25 11:12:58 +00:00
*/
2023-09-13 12:21:49 +00:00
#include <rte_bus.h>
2019-06-25 11:12:58 +00:00
#include <rte_ethdev.h>
2025-01-10 11:50:43 +00:00
#include "commands.h"
2019-06-25 11:12:58 +00:00
2025-01-10 11:50:43 +00:00
void cmd_help_parsed(__rte_unused void *parsed_result,
2019-06-25 11:12:58 +00:00
struct cmdline *cl,
2021-02-05 08:48:47 +00:00
__rte_unused void *data)
2019-06-25 11:12:58 +00:00
{
cmdline_printf(cl,
"commands:\n"
"- attach <devargs>\n"
"- detach <devargs>\n"
"- list\n\n");
}
2025-01-10 11:50:43 +00:00
void
cmd_quit_parsed(__rte_unused void *parsed_result,
2019-06-25 11:12:58 +00:00
struct cmdline *cl,
2021-02-05 08:48:47 +00:00
__rte_unused void *data)
2019-06-25 11:12:58 +00:00
{
cmdline_quit(cl);
}
2025-01-10 11:50:43 +00:00
void
cmd_list_parsed(__rte_unused void *parsed_result,
2019-06-25 11:12:58 +00:00
struct cmdline *cl,
2021-02-05 08:48:47 +00:00
__rte_unused void *data)
2019-06-25 11:12:58 +00:00
{
uint16_t port_id;
char dev_name[RTE_DEV_NAME_MAX_LEN];
cmdline_printf(cl, "list all etherdev\n");
RTE_ETH_FOREACH_DEV(port_id) {
rte_eth_dev_get_name_by_port(port_id, dev_name);
if (strlen(dev_name) > 0)
cmdline_printf(cl, "%d\t%s\n", port_id, dev_name);
else
printf("empty dev_name is not expected!\n");
}
}
2025-01-10 11:50:43 +00:00
void
cmd_attach_parsed(void *parsed_result,
2019-06-25 11:12:58 +00:00
struct cmdline *cl,
2021-02-05 08:48:47 +00:00
__rte_unused void *data)
2019-06-25 11:12:58 +00:00
{
2025-01-10 11:50:43 +00:00
struct cmd_attach_result *res = parsed_result;
2019-06-25 11:12:58 +00:00
struct rte_devargs da;
memset(&da, 0, sizeof(da));
if (rte_devargs_parsef(&da, "%s", res->devargs)) {
cmdline_printf(cl, "cannot parse devargs\n");
return;
}
2023-09-13 12:21:49 +00:00
if (!rte_eal_hotplug_add(rte_bus_name(da.bus), da.name, da.args))
2019-06-25 11:12:58 +00:00
cmdline_printf(cl, "attached device %s\n", da.name);
else
cmdline_printf(cl, "failed to attached device %s\n",
da.name);
2022-09-06 04:00:10 +00:00
rte_devargs_reset(&da);
2019-06-25 11:12:58 +00:00
}
2025-01-10 11:50:43 +00:00
void
cmd_detach_parsed(void *parsed_result,
2019-06-25 11:12:58 +00:00
struct cmdline *cl,
2021-02-05 08:48:47 +00:00
__rte_unused void *data)
2019-06-25 11:12:58 +00:00
{
2025-01-10 11:50:43 +00:00
struct cmd_detach_result *res = parsed_result;
2019-06-25 11:12:58 +00:00
struct rte_devargs da;
memset(&da, 0, sizeof(da));
if (rte_devargs_parsef(&da, "%s", res->devargs)) {
cmdline_printf(cl, "cannot parse devargs\n");
return;
}
printf("detaching...\n");
2023-09-13 12:21:49 +00:00
if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
2019-06-25 11:12:58 +00:00
cmdline_printf(cl, "detached device %s\n",
da.name);
else
2022-09-02 04:40:05 +00:00
cmdline_printf(cl, "failed to detach device %s\n",
2019-06-25 11:12:58 +00:00
da.name);
2022-09-06 04:00:10 +00:00
rte_devargs_reset(&da);
2019-06-25 11:12:58 +00:00
}