fix defects of macro in VF
cover fix defects of macro in VF
The defects of UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT exist. If latest is less than last, we will get wrong result. The issues exist only in ixgbe and e1000 NICs.
Guinan Sun (2):
net/ixgbe: fix defects of macro in VF
net/e1000: fix defects of macro in VF
drivers/net/e1000/igb_ethdev.c | 14 +++++++++++--- drivers/net/ixgbe/ixgbe_ethdev.c | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 net/ixgbe: fix defects of macro in VF
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/")
Signed-off-by Guinan Sun <[email protected]>
--- drivers/net/ixgbe/ixgbe_ethdev.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +18 -2
@@ -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; \ }
Signature · 1 line
2.17.1
PATCH 2/2 net/e1000: fix defects of macro in VF
In reply to Guinan SunThe 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 d15fcf76c8b7 ("e1000: move to drivers/net/")
Signed-off-by Guinan Sun <[email protected]>
--- drivers/net/e1000/igb_ethdev.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/net/e1000/igb_ethdev.c +11 -3
@@ -47,6 +47,8 @@#define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)#define IGB_8_BIT_WIDTH CHAR_BIT#define IGB_8_BIT_MASK UINT8_MAX +#define IGB_32_BIT_WIDTH (CHAR_BIT * 4) +#define IGB_32_BIT_MASK RTE_LEN2MASK(IGB_32_BIT_WIDTH, uint32_t)/* Additional timesync values. */ #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffffULL
@@ -263,9 +265,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);*/ #define UPDATE_VF_STAT (reg, last, cur) \ { \ - u32 latest = E1000_READ_REG(hw, reg); \ - cur += (latest - last) & UINT_MAX; \ - last = latest; \ + uint64_t latest = E1000_READ_REG(hw, reg); \ + uint64_t stat = 0; \ + if (latest >= last) \ + stat = latest - last; \ + else \ + stat = (uint64_t)((latest + \ + ((uint64_t)1 << IGB_32_BIT_WIDTH)) - last);\ + cur += stat & IGB_32_BIT_MASK; \ + last = latest; \ }#define IGB_FC_PAUSE_TIME 0x0680
Signature · 1 line
2.17.1