From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB2CDA00E6 for ; Wed, 10 Jul 2019 15:07:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D4D88231E; Wed, 10 Jul 2019 15:07:17 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id F09AF14E8 for ; Wed, 10 Jul 2019 15:07:15 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6AD6wMD009186; Wed, 10 Jul 2019 06:07:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0818; bh=zqxqW6arYvvR95aSIMuJk+l4GNKSz+Bn/KL1HaPCr9I=; b=gVqO+XWffjVFKz0MKrhVamr3BQ47uGmJtkgRVtaFCoLPkuPikHNuA7dAV/eQULJW/Ecb bmdylVzBzew8C2Dhd7xlQ9+ocF1c1984VUu9wWSvGdgWPKIz7ZJ6HpuhHyG2W7A/AOhn 60cMsZhvDiKWwlAmJIjAZKDPh08YlegirnPQke2s4ud9Fi3VFc7nWJv43F/7QgL9pUwq dxLqFhBWLck07GsPeVENw35xGYKR89tR/W78spUOgfgIMQNUHjYRGknfLcGC5ytq610O kbRMG8io74Ys6tUOnOddwlU8V6/hHmumJtA4FPvw9baEpBTVlFVPvkwwTr+fBE+XyjLQ mA== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2tn7d7sy45-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 10 Jul 2019 06:07:14 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 10 Jul 2019 06:07:13 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 10 Jul 2019 06:07:13 -0700 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id 916B63F7041; Wed, 10 Jul 2019 06:07:10 -0700 (PDT) From: Nithin Dabilpuram To: , Wenzhuo Lu , Jingjing Wu , Bernard Iremonger , John McNamara , "Marko Kovacevic" CC: , , Nithin Dabilpuram Date: Wed, 10 Jul 2019 18:37:04 +0530 Message-ID: <20190710130704.131936-1-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20190513112112.7069-1-ndabilpuram@marvell.com> References: <20190513112112.7069-1-ndabilpuram@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-07-10_05:, , signatures=0 Subject: [dpdk-dev] [PATCH v2] app/testpmd: add device related cmds X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" With the latest published interface of rte_eal_hotplug_[add,remove](), and rte_eth_dev_close(), rte_eth_dev_close() would cleanup all the data structures of port's eth dev leaving the device common resource intact if RTE_ETH_DEV_CLOSE_REMOVE is set in dev flags. So a new command "detach device" (~hotplug remove) to work, with device identifier like "port attach" is added to be able to detach closed devices. Also to display currently probed devices, another command "show device info |all" is also added as a part of this change. Signed-off-by: Nithin Dabilpuram --- app/test-pmd/cmdline.c | 88 +++++++++++++++++++++++++++++ app/test-pmd/config.c | 73 ++++++++++++++++++++++++ app/test-pmd/testpmd.c | 45 +++++++++++++++ app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 64 +++++++++++++++++++++ 5 files changed, 272 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 01dd45f..e10e82a 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1493,6 +1493,47 @@ cmdline_parse_inst_t cmd_operate_detach_port = { }, }; +/* *** detach device by identifier *** */ +struct cmd_operate_detach_device_result { + cmdline_fixed_string_t device; + cmdline_fixed_string_t keyword; + cmdline_fixed_string_t identifier; +}; + +static void cmd_operate_detach_device_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_operate_detach_device_result *res = parsed_result; + + if (!strcmp(res->keyword, "detach")) + detach_device(res->identifier); + else + printf("Unknown parameter\n"); +} + +cmdline_parse_token_string_t cmd_operate_detach_device_device = + TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, + device, "device"); +cmdline_parse_token_string_t cmd_operate_detach_device_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, + keyword, "detach"); +cmdline_parse_token_string_t cmd_operate_detach_device_identifier = + TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, + identifier, NULL); + +cmdline_parse_inst_t cmd_operate_detach_device = { + .f = cmd_operate_detach_device_parsed, + .data = NULL, + .help_str = "device detach :" + "(identifier: pci address or virtual dev name)", + .tokens = { + (void *)&cmd_operate_detach_device_device, + (void *)&cmd_operate_detach_device_keyword, + (void *)&cmd_operate_detach_device_identifier, + NULL, + }, +}; /* *** configure speed for all ports *** */ struct cmd_config_speed_all { cmdline_fixed_string_t port; @@ -7456,6 +7497,51 @@ cmdline_parse_inst_t cmd_showport = { }, }; +/* *** SHOW DEVICE INFO *** */ +struct cmd_showdevice_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t device; + cmdline_fixed_string_t what; + cmdline_fixed_string_t identifier; +}; + +static void cmd_showdevice_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_showdevice_result *res = parsed_result; + if (!strcmp(res->what, "info")) { + if (!strcmp(res->identifier, "all")) + device_infos_display(NULL); + else + device_infos_display(res->identifier); + } +} + +cmdline_parse_token_string_t cmd_showdevice_show = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show, + "show"); +cmdline_parse_token_string_t cmd_showdevice_device = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device"); +cmdline_parse_token_string_t cmd_showdevice_what = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what, + "info"); +cmdline_parse_token_string_t cmd_showdevice_identifier = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, + identifier, NULL); + +cmdline_parse_inst_t cmd_showdevice = { + .f = cmd_showdevice_parsed, + .data = NULL, + .help_str = "show device info |all", + .tokens = { + (void *)&cmd_showdevice_show, + (void *)&cmd_showdevice_device, + (void *)&cmd_showdevice_what, + (void *)&cmd_showdevice_identifier, + NULL, + }, +}; /* *** SHOW QUEUE INFO *** */ struct cmd_showqueue_result { cmdline_fixed_string_t show; @@ -18723,6 +18809,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_showport, (cmdline_parse_inst_t *)&cmd_showqueue, (cmdline_parse_inst_t *)&cmd_showportall, + (cmdline_parse_inst_t *)&cmd_showdevice, (cmdline_parse_inst_t *)&cmd_showcfg, (cmdline_parse_inst_t *)&cmd_showfwdall, (cmdline_parse_inst_t *)&cmd_start, @@ -18811,6 +18898,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_operate_specific_port, (cmdline_parse_inst_t *)&cmd_operate_attach_port, (cmdline_parse_inst_t *)&cmd_operate_detach_port, + (cmdline_parse_inst_t *)&cmd_operate_detach_device, (cmdline_parse_inst_t *)&cmd_set_port_setup_on, (cmdline_parse_inst_t *)&cmd_config_speed_all, (cmdline_parse_inst_t *)&cmd_config_speed_specific, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 1d80470..537e73f 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -386,6 +386,79 @@ tx_queue_infos_display(portid_t port_id, uint16_t queue_id) printf("\n"); } +static int bus_match_all(const struct rte_bus *bus, const void *data) +{ + RTE_SET_USED(bus); + RTE_SET_USED(data); + return 0; +} + +void +device_infos_display(const char *identifier) +{ + static const char *info_border = "*********************"; + struct rte_bus *start = NULL, *next; + struct rte_dev_iterator dev_iter; + char name[RTE_ETH_NAME_MAX_LEN]; + struct rte_ether_addr mac_addr; + struct rte_device *dev; + struct rte_devargs da; + portid_t port_id; + char devstr[128]; + + memset(&da, 0, sizeof(da)); + if (!identifier) + goto skip_parse; + + if (rte_devargs_parsef(&da, "%s", identifier)) { + printf("cannot parse identifier\n"); + if (da.args) + free(da.args); + return; + } + +skip_parse: + while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) { + + start = next; + if (identifier && da.bus != next) + continue; + + /* Skip buses that don't have iterate method */ + if (!next->dev_iterate) + continue; + + snprintf(devstr, sizeof(devstr), "bus=%s", next->name); + RTE_DEV_FOREACH(dev, devstr, &dev_iter) { + + if (!dev->driver) + continue; + /* Check for matching device if identifier is present */ + if (identifier && + strncmp(da.name, dev->name, strlen(dev->name))) + continue; + printf("\n%s Infos for device %s %s\n", + info_border, dev->name, info_border); + printf("Bus name: %s", dev->bus->name); + printf("\nDriver name: %s", dev->driver->name); + printf("\nDevargs: %s", + dev->devargs ? dev->devargs->args : ""); + printf("\nConnect to socket: %d", dev->numa_node); + printf("\n"); + + /* List ports with matching device name */ + RTE_ETH_FOREACH_DEV_OF(port_id, dev) { + rte_eth_macaddr_get(port_id, &mac_addr); + printf("\n\tPort id: %-2d", port_id); + print_ethaddr("\n\tMAC address: ", &mac_addr); + rte_eth_dev_get_name_by_port(port_id, name); + printf("\n\tDevice name: %s", name); + printf("\n"); + } + } + }; +} + void port_infos_display(portid_t port_id) { diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 3ed3523..a3b1542 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2476,6 +2476,51 @@ detach_port_device(portid_t port_id) } void +detach_device(char *identifier) +{ + struct rte_dev_iterator iterator; + struct rte_devargs da; + portid_t port_id; + + printf("Removing a device...\n"); + + memset(&da, 0, sizeof(da)); + if (rte_devargs_parsef(&da, "%s", identifier)) { + printf("cannot parse identifier\n"); + if (da.args) + free(da.args); + return; + } + + RTE_ETH_FOREACH_MATCHING_DEV(port_id, identifier, &iterator) { + if (ports[port_id].port_status != RTE_PORT_CLOSED) { + if (ports[port_id].port_status != RTE_PORT_STOPPED) { + printf("Port %u not stopped\n", port_id); + return; + } + + /* sibling ports are forced to be closed */ + if (ports[port_id].flow_list) + port_flow_flush(port_id); + ports[port_id].port_status = RTE_PORT_CLOSED; + printf("Port %u is now closed\n", port_id); + } + } + + if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) { + TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n", + da.name, da.bus->name); + return; + } + + remove_invalid_ports(); + + printf("Device %s is detached\n", identifier); + printf("Now total ports is %d\n", nb_ports); + printf("Done\n"); +} + +void pmd_test_exit(void) { portid_t pt_id; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e3a6f7c..93bed6d 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -689,6 +689,7 @@ void nic_stats_clear(portid_t port_id); void nic_xstats_display(portid_t port_id); void nic_xstats_clear(portid_t port_id); void nic_stats_mapping_display(portid_t port_id); +void device_infos_display(const char *identifier); void port_infos_display(portid_t port_id); void port_summary_display(portid_t port_id); void port_summary_header_display(void); @@ -788,6 +789,7 @@ void stop_port(portid_t pid); void close_port(portid_t pid); void reset_port(portid_t pid); void attach_port(char *identifier); +void detach_device(char *identifier); void detach_port_device(portid_t port_id); int all_ports_stopped(void); int port_is_stopped(portid_t port_id); diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index ebab2f1..04b9a31 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -467,6 +467,29 @@ Show Tx metadata value set for a specific port:: testpmd> show port (port_id) tx_metadata +show device info +~~~~~~~~~~~~~~~~ + +Show general information about devices probed:: + + testpmd> show device info (|all) + +For example: + +.. code-block:: console + + testpmd> show device info net_pcap0 + + ********************* Infos for device net_pcap0 ********************* + Bus name: vdev + Driver name: net_pcap + Devargs: iface=enP2p6s0,phy_mac=1 + Connect to socket: -1 + + Port id: 2 + MAC address: 1E:37:93:28:04:B8 + Device name: net_pcap0 + dump physmem ~~~~~~~~~~~~ @@ -2289,6 +2312,47 @@ hash of input [IP] packets received on port:: ipv6-udp-ex ) +Device Functions +---------------- + +The following sections show functions for device operations. + +device detach +~~~~~~~~~~~~~ + +Detach a device specified by pci address or virtual device args:: + + testpmd> device detach (identifier) + +Before detaching a device associated with ports, the ports should be stopped and closed. + +For example, to detach a pci device whose address is 0002:03:00.0. + +.. code-block:: console + + testpmd> device detach 0002:03:00.0 + Removing a device... + Port 1 is now closed + EAL: Releasing pci mapped resource for 0002:03:00.0 + EAL: Calling pci_unmap_resource for 0002:03:00.0 at 0x218a050000 + EAL: Calling pci_unmap_resource for 0002:03:00.0 at 0x218c050000 + Device 0002:03:00.0 is detached + Now total ports is 1 + +For example, to detach a port created by pcap PMD. + +.. code-block:: console + + testpmd> device detach net_pcap0 + Removing a device... + Port 0 is now closed + Device net_pcap0 is detached + Now total ports is 0 + Done + +In this case, identifier is ``net_pcap0``. +This identifier format is the same as ``--vdev`` format of DPDK applications. + Link Bonding Functions ---------------------- -- 2.8.4