From patchwork Thu Sep 15 12:45:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lihuisong (C)" X-Patchwork-Id: 116354 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A5BBCA00C5; Thu, 15 Sep 2022 14:47:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA46942847; Thu, 15 Sep 2022 14:47:00 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 901C440223 for ; Thu, 15 Sep 2022 14:46:55 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MSxgd6yZkzlVw2; Thu, 15 Sep 2022 20:42:53 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 15 Sep 2022 20:46:53 +0800 Received: from localhost.localdomain (10.28.79.22) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 15 Sep 2022 20:46:52 +0800 From: Huisong Li To: CC: , , , , Subject: [PATCH V2 5/6] app/testpmd: support attach and detach port for MP Date: Thu, 15 Sep 2022 20:45:21 +0800 Message-ID: <20220915124522.5407-6-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20220915124522.5407-1-lihuisong@huawei.com> References: <20220825024425.10534-1-lihuisong@huawei.com> <20220915124522.5407-1-lihuisong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch supports attach and detach port in primary and secondary process. Signed-off-by: Huisong Li Signed-off-by: Dongdong Liu --- app/test-pmd/testpmd.c | 76 +++++++++++++++++---------- app/test-pmd/testpmd.h | 1 - drivers/net/bonding/bonding_testpmd.c | 1 - 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 1605e34f35..10b330e33c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -3323,9 +3323,6 @@ reset_port(portid_t pid) void attach_port(char *identifier) { - portid_t pi; - struct rte_dev_iterator iterator; - printf("Attaching a new port...\n"); if (identifier == NULL) { @@ -3337,24 +3334,6 @@ attach_port(char *identifier) TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier); return; } - - /* first attach mode: event */ - if (setup_on_probe_event) { - /* new ports are detected on RTE_ETH_EVENT_NEW event */ - for (pi = 0; pi < RTE_MAX_ETHPORTS; pi++) - if (ports[pi].port_status == RTE_PORT_HANDLING && - ports[pi].need_setup != 0) - setup_attached_port(pi); - return; - } - - /* second attach mode: iterator */ - RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) { - /* setup ports matching the devargs used for probing */ - if (port_is_forwarding(pi)) - continue; /* port was already attached before */ - setup_attached_port(pi); - } } static void @@ -3377,7 +3356,6 @@ setup_attached_port(portid_t pi) ports_ids[nb_ports++] = pi; fwd_ports_ids[nb_fwd_ports++] = pi; nb_cfg_ports = nb_fwd_ports; - ports[pi].need_setup = 0; ports[pi].port_status = RTE_PORT_STOPPED; printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports); @@ -3411,11 +3389,10 @@ detach_device(struct rte_device *dev) TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name); return; } - remove_invalid_ports(); printf("Device is detached\n"); - printf("Now total ports is %d\n", nb_ports); printf("Done\n"); + return; } @@ -3481,11 +3458,9 @@ detach_devargs(char *identifier) return; } - remove_invalid_ports(); - printf("Device %s is detached\n", identifier); - printf("Now total ports is %d\n", nb_ports); printf("Done\n"); + rte_devargs_reset(&da); } @@ -3649,11 +3624,52 @@ rmv_port_callback(void *arg) struct rte_device *device = dev_info.device; close_port(port_id); detach_device(device); /* might be already removed or have more ports */ + remove_invalid_ports(); + printf("Now total ports is %d\n", nb_ports); } if (need_to_start) start_packet_forwarding(0); } +static void config_attached_port(portid_t port_id) +{ + struct rte_dev_iterator iterator; + struct rte_eth_dev_info dev_info; + portid_t pi; + int ret; + + /* first attach mode: event */ + if (setup_on_probe_event) { + /* new ports are detected on RTE_ETH_EVENT_NEW event */ + setup_attached_port(port_id); + return; + } + + ret = eth_dev_info_get_print_err(port_id, &dev_info); + if (ret != 0) { + TESTPMD_LOG(ERR, + "Failed to get device info for port %d, not detaching\n", + port_id); + return; + } + /* second attach mode: iterator */ + RTE_ETH_FOREACH_MATCHING_DEV(pi, dev_info.device->name, &iterator) { + /* setup ports matching the devargs used for probing */ + if (port_is_forwarding(port_id)) + continue; /* port was already attached before */ + setup_attached_port(port_id); + } +} + +static void +remove_invalid_ports_callback(void *arg) +{ + RTE_SET_USED(arg); + + remove_invalid_ports(); + printf("Now total ports is %d\n", nb_ports); +} + /* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, @@ -3678,8 +3694,7 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, switch (type) { case RTE_ETH_EVENT_NEW: - ports[port_id].need_setup = 1; - ports[port_id].port_status = RTE_PORT_HANDLING; + config_attached_port(port_id); break; case RTE_ETH_EVENT_INTR_RMV: if (rte_eal_alarm_set(100000, @@ -3690,6 +3705,9 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, case RTE_ETH_EVENT_DESTROY: ports[port_id].port_status = RTE_PORT_CLOSED; printf("Port %u is closed\n", port_id); + if (rte_eal_alarm_set(100000, remove_invalid_ports_callback, + (void *)(intptr_t)port_id)) + fprintf(stderr, "Could not set up deferred device released\n"); break; case RTE_ETH_EVENT_RX_AVAIL_THRESH: { uint16_t rxq_id; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ddf5e21849..22261f20a2 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -278,7 +278,6 @@ struct rte_port { uint16_t tx_vlan_id;/**< The tag ID */ uint16_t tx_vlan_id_outer;/**< The outer tag ID */ volatile uint16_t port_status; /**< port started or not */ - uint8_t need_setup; /**< port just attached */ uint8_t need_reconfig; /**< need reconfiguring port or not */ uint8_t need_reconfig_queues; /**< need reconfiguring queues or not */ uint8_t rss_flag; /**< enable rss or not */ diff --git a/drivers/net/bonding/bonding_testpmd.c b/drivers/net/bonding/bonding_testpmd.c index 3941f4cf23..ed1a278a44 100644 --- a/drivers/net/bonding/bonding_testpmd.c +++ b/drivers/net/bonding/bonding_testpmd.c @@ -763,7 +763,6 @@ static void cmd_create_bonded_device_parsed(void *parsed_result, port_id, rte_strerror(-ret)); ports[port_id].bond_flag = 1; - ports[port_id].need_setup = 0; ports[port_id].port_status = RTE_PORT_STOPPED; }