From patchwork Mon Sep 10 13:51:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 44514 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E8EC44CC3; Mon, 10 Sep 2018 15:50:21 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id D0EF61B19 for ; Mon, 10 Sep 2018 15:50:16 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 06:50:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="261342422" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by fmsmga005.fm.intel.com with ESMTP; 10 Sep 2018 06:50:13 -0700 From: Qi Zhang To: thomas@monjalon.net, konstantin.ananyev@intel.com, declan.doherty@intel.com, ferruh.yigit@intel.com Cc: dev@dpdk.org, benjamin.h.shelton@intel.com, narender.vangati@intel.com, Qi Zhang Date: Mon, 10 Sep 2018 21:51:07 +0800 Message-Id: <20180910135107.6286-3-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180910135107.6286-1-qi.z.zhang@intel.com> References: <20180910135107.6286-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [RFC v2 2/2] testpmd: enable async device reset 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" rte_eth_dev_reset is claimed as an async API, so re-work on the device reset handling. Signed-off-by: Qi Zhang --- app/test-pmd/testpmd.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index ee48db2a3..8d4d7b4f9 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1918,6 +1918,54 @@ close_port(portid_t pid) printf("Done\n"); } +static int reset_ret; +static int reset_done; + +static int +on_reset_complete(__rte_unused uint16_t port_id, + __rte_unused enum rte_eth_event_type event, + __rte_unused void *cb_arg, + void *ret_param) +{ + RTE_ASSERT(event == RTE_ETH_EVENT_RESET_COMPLETE); + + reset_ret = *(int *)ret_param; + reset_done = 1; + return 0; +} + +static int +do_dev_reset_sync(portid_t pid) +{ + int ret; + + ret = rte_eth_dev_callback_register(pid, + RTE_ETH_EVENT_RESET_COMPLETE, + on_reset_complete, NULL); + + if (ret) { + printf("Fail to reigster callback function\n"); + return ret; + } + + reset_done = 0; + ret = rte_eth_dev_reset(pid); + if (ret) + goto finish; + + while (!reset_done) + rte_delay_ms(10); + + ret = reset_ret; + +finish: + rte_eth_dev_callback_unregister(pid, + RTE_ETH_EVENT_RESET_COMPLETE, + on_reset_complete, NULL); + + return ret; +} + void reset_port(portid_t pid) { @@ -1946,7 +1994,7 @@ reset_port(portid_t pid) continue; } - diag = rte_eth_dev_reset(pi); + diag = do_dev_reset_sync(pi); if (diag == 0) { port = &ports[pi]; port->need_reconfig = 1;