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 4D933A00C5; Thu, 7 May 2020 08:37:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C2C9D1DA20; Thu, 7 May 2020 08:37:32 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 570391D9B3; Thu, 7 May 2020 08:37:30 +0200 (CEST) IronPort-SDR: PO63jJzVpPVffp3FpbArzkZ6kfmG7X1t9Oyf9bRskgxJG2aGtkSXsaeeAIyG8x+BZrUjKAKeiK VxHzvE22xExA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2020 23:37:29 -0700 IronPort-SDR: RuATW8fuvfaLRW+JnZ1iIzhlnPzkwqJzgDSxPNIIsfLvqTBWM7LHchISm4Mytt9woZEV0NQp3f bozxZLzgCWBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,362,1583222400"; d="scan'208";a="278497146" Received: from dpdk.sh.intel.com ([10.239.255.59]) by orsmga002.jf.intel.com with ESMTP; 06 May 2020 23:37:28 -0700 From: Guinan Sun To: dev@dpdk.org Cc: Guinan Sun , stable@dpdk.org Date: Thu, 7 May 2020 06:16:41 +0000 Message-Id: <20200507061642.64969-2-guinanx.sun@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200507061642.64969-1-guinanx.sun@intel.com> References: <20200507061642.64969-1-guinanx.sun@intel.com> Subject: [dpdk-dev] [PATCH 1/2] net/ixgbe: fix defects of macro in VF 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" The defects in the macros UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT exist. If latest is less than last, we will get wrong result. The patch fixes the defect. Fixes: abf7275bbaa2 ("ixgbe: move to drivers/net/") Cc: stable@dpdk.org Signed-off-by: Guinan Sun --- drivers/net/ixgbe/ixgbe_ethdev.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index cf5f1fe70..08a964399 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -94,6 +94,10 @@ #define IXGBE_4_BIT_MASK RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t) #define IXGBE_8_BIT_WIDTH CHAR_BIT #define IXGBE_8_BIT_MASK UINT8_MAX +#define IXGBE_32_BIT_WIDTH (CHAR_BIT * 4) +#define IXGBE_32_BIT_MASK RTE_LEN2MASK(IXGBE_32_BIT_WIDTH, uint32_t) +#define IXGBE_36_BIT_WIDTH (CHAR_BIT * 4 + IXGBE_4_BIT_WIDTH) +#define IXGBE_36_BIT_MASK RTE_LEN2MASK(IXGBE_36_BIT_WIDTH, uint64_t) #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */ @@ -388,7 +392,13 @@ static int ixgbe_wait_for_link_up(struct ixgbe_hw *hw); #define UPDATE_VF_STAT(reg, last, cur) \ { \ uint32_t latest = IXGBE_READ_REG(hw, reg); \ - cur += (latest - last) & UINT_MAX; \ + u64 stat = 0; \ + if (latest >= last) \ + stat = latest - last; \ + else \ + stat = (u64)((latest + \ + ((u64)1 << IXGBE_32_BIT_WIDTH)) - last);\ + cur += stat & IXGBE_32_BIT_MASK; \ last = latest; \ } @@ -397,7 +407,13 @@ static int ixgbe_wait_for_link_up(struct ixgbe_hw *hw); u64 new_lsb = IXGBE_READ_REG(hw, lsb); \ u64 new_msb = IXGBE_READ_REG(hw, msb); \ u64 latest = ((new_msb << 32) | new_lsb); \ - cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \ + u64 stat = 0; \ + if (latest >= last) \ + stat = latest - last; \ + else \ + stat = (u64)((latest + \ + ((u64)1 << IXGBE_36_BIT_WIDTH)) - last); \ + cur += stat & IXGBE_36_BIT_MASK; \ last = latest; \ } -- 2.17.1