1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018-2023 Intel Corporation. 3 */ 4 5 #include <rte_bus.h> 6 #include <rte_ethdev.h> 7 #include "commands.h" 8 9 void cmd_help_parsed(__rte_unused void *parsed_result, 10 struct cmdline *cl, 11 __rte_unused void *data) 12 { 13 cmdline_printf(cl, 14 "commands:\n" 15 "- attach <devargs>\n" 16 "- detach <devargs>\n" 17 "- list\n\n"); 18 } 19 20 void 21 cmd_quit_parsed(__rte_unused void *parsed_result, 22 struct cmdline *cl, 23 __rte_unused void *data) 24 { 25 cmdline_quit(cl); 26 } 27 28 void 29 cmd_list_parsed(__rte_unused void *parsed_result, 30 struct cmdline *cl, 31 __rte_unused void *data) 32 { 33 uint16_t port_id; 34 char dev_name[RTE_DEV_NAME_MAX_LEN]; 35 36 cmdline_printf(cl, "list all etherdev\n"); 37 38 RTE_ETH_FOREACH_DEV(port_id) { 39 rte_eth_dev_get_name_by_port(port_id, dev_name); 40 if (strlen(dev_name) > 0) 41 cmdline_printf(cl, "%d\t%s\n", port_id, dev_name); 42 else 43 printf("empty dev_name is not expected!\n"); 44 } 45 } 46 47 void 48 cmd_attach_parsed(void *parsed_result, 49 struct cmdline *cl, 50 __rte_unused void *data) 51 { 52 struct cmd_attach_result *res = parsed_result; 53 struct rte_devargs da; 54 55 memset(&da, 0, sizeof(da)); 56 57 if (rte_devargs_parsef(&da, "%s", res->devargs)) { 58 cmdline_printf(cl, "cannot parse devargs\n"); 59 return; 60 } 61 62 if (!rte_eal_hotplug_add(rte_bus_name(da.bus), da.name, da.args)) 63 cmdline_printf(cl, "attached device %s\n", da.name); 64 else 65 cmdline_printf(cl, "failed to attached device %s\n", 66 da.name); 67 rte_devargs_reset(&da); 68 } 69 70 void 71 cmd_detach_parsed(void *parsed_result, 72 struct cmdline *cl, 73 __rte_unused void *data) 74 { 75 struct cmd_detach_result *res = parsed_result; 76 struct rte_devargs da; 77 78 memset(&da, 0, sizeof(da)); 79 80 if (rte_devargs_parsef(&da, "%s", res->devargs)) { 81 cmdline_printf(cl, "cannot parse devargs\n"); 82 return; 83 } 84 85 printf("detaching...\n"); 86 if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name)) 87 cmdline_printf(cl, "detached device %s\n", 88 da.name); 89 else 90 cmdline_printf(cl, "failed to detach device %s\n", 91 da.name); 92 rte_devargs_reset(&da); 93 } 94