From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <cliang18@shecgisg004.sh.intel.com>
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id 04A1D7E23
 for <dev@dpdk.org>; Wed,  1 Apr 2015 04:34:04 +0200 (CEST)
Received: from fmsmga002.fm.intel.com ([10.253.24.26])
 by orsmga101.jf.intel.com with ESMTP; 31 Mar 2015 19:33:45 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.11,503,1422950400"; d="scan'208";a="701198789"
Received: from shvmail01.sh.intel.com ([10.239.29.42])
 by fmsmga002.fm.intel.com with ESMTP; 31 Mar 2015 19:33:44 -0700
Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com
 [10.239.29.89])
 by shvmail01.sh.intel.com with ESMTP id t312Xfvq012412;
 Wed, 1 Apr 2015 10:33:41 +0800
Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1])
 by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id
 t312Xci8008706; Wed, 1 Apr 2015 10:33:40 +0800
Received: (from cliang18@localhost)
 by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t312Xbbx008702;
 Wed, 1 Apr 2015 10:33:37 +0800
From: Cunming Liang <cunming.liang@intel.com>
To: dev@dpdk.org
Date: Wed,  1 Apr 2015 10:33:34 +0800
Message-Id: <1427855614-8654-1-git-send-email-cunming.liang@intel.com>
X-Mailer: git-send-email 1.7.4.1
Subject: [dpdk-dev] [PATCH] i40e: fix no effect wait_to_complete on link_get
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 01 Apr 2015 02:34:05 -0000

API *rte_eth_link_get* expect to call a wait to complete link_update.
That's the difference between *rte_eth_link_get_nowait*.
The patch fixes the issue that i40e link_update ignores the wait_to_complete flag.
The issue impacts those applications calling rte_eth_link_get to get wrong intermediate link status.

Signed-off-by: Cunming Liang <cunming.liang@intel.com>
---
 lib/librte_pmd_i40e/i40e_ethdev.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/librte_pmd_i40e/i40e_ethdev.c b/lib/librte_pmd_i40e/i40e_ethdev.c
index 00d044f..6b8f96e 100644
--- a/lib/librte_pmd_i40e/i40e_ethdev.c
+++ b/lib/librte_pmd_i40e/i40e_ethdev.c
@@ -1081,28 +1081,37 @@ i40e_dev_set_link_down(__rte_unused struct rte_eth_dev *dev)
 
 int
 i40e_dev_link_update(struct rte_eth_dev *dev,
-		     __rte_unused int wait_to_complete)
+		     int wait_to_complete)
 {
+#define CHECK_INTERVAL 100  /* 100ms */
+#define MAX_REPEAT_TIME 10  /* 1s (10 * 100ms) in total */
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_link_status link_status;
 	struct rte_eth_link link, old;
 	int status;
+	unsigned rep_cnt = MAX_REPEAT_TIME;
 
 	memset(&link, 0, sizeof(link));
 	memset(&old, 0, sizeof(old));
 	memset(&link_status, 0, sizeof(link_status));
 	rte_i40e_dev_atomic_read_link_status(dev, &old);
 
-	/* Get link status information from hardware */
-	status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
-	if (status != I40E_SUCCESS) {
-		link.link_speed = ETH_LINK_SPEED_100;
-		link.link_duplex = ETH_LINK_FULL_DUPLEX;
-		PMD_DRV_LOG(ERR, "Failed to get link info");
-		goto out;
-	}
+	do {
+		/* Get link status information from hardware */
+		status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
+		if (status != I40E_SUCCESS) {
+			link.link_speed = ETH_LINK_SPEED_100;
+			link.link_duplex = ETH_LINK_FULL_DUPLEX;
+			PMD_DRV_LOG(ERR, "Failed to get link info");
+			goto out;
+		}
+
+		link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
+		if (!wait_to_complete)
+			break;
 
-	link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
+		rte_delay_ms(CHECK_INTERVAL);
+	} while (!link.link_status && rep_cnt--);
 
 	if (!link.link_status)
 		goto out;
-- 
1.8.1.4