r8169: fix PAUSE frames blasting issue
cover r8169: fix PAUSE frames blasting issue
This series of patches are used to fix PAUSE frames blasting issue.
ChunHao Lin (2):
r8169: enable rtl8125b pause slot
r8169: fix deadlock in "r8169_phylink_handler"
drivers/net/ethernet/realtek/r8169_main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/2 r8169: enable rtl8125b pause slot
When FIFO reach near full state, device will issue pause frame. If pause slot is enabled(set to 1), in this time, device will issue pause frame once. But if pause slot is disabled(set to 0), device will keep sending pause frames until FIFO reach near empty state.
When pause slot is disabled, if there is no one to handle receive packets (ex. unexpected shutdown), device FIFO will reach near full state and keep sending pause frames. That will impact entire local area network.
In this patch default enable pause slot to prevent this kind of situation.
--- drivers/net/ethernet/realtek/r8169_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +6 -1
@@ -196,6 +196,7 @@ enum rtl_registers {/* No threshold before first PCI xfer */ #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)#define RX_EARLY_OFF (1 << 11) +#define RX_PAUSE_SLOT_ON (1 << 11)#define RXCFG_DMA_SHIFT 8/* Unlimited maximum PCI burst. */ #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)
@@ -2305,9 +2306,13 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp) case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_MULTI_EN |RX_DMA_BURST |RX_EARLY_OFF );break ; - case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_63: +case RTL_GIGA_MAC_VER_61 :RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST );break ; +case RTL_GIGA_MAC_VER_63 : +RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST | +RX_PAUSE_SLOT_ON ); +break ;default :RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_DMA_BURST );break ;
Signature · 1 line
2.39.2
Heiner Kallweit
maintainerRe: [PATCH net 1/2] r8169: enable rtl8125b pause slot
Quoted 5 lines · ChunHao Lin
When FIFO reach near full state, device will issue pause frame. If pause slot is enabled(set to 1), in this time, device will issue pause frame once. But if pause slot is disabled(set to 0), device will keep sending pause frames until FIFO reach near empty state.
Quoted 8 lines
When pause slot is disabled, if there is no one to handle receive packets (ex. unexpected shutdown), device FIFO will reach near full state and keep sending pause frames. That will impact entire local area network.
In this patch default enable pause slot to prevent this kind of situation.
Can this change have any side effect? I'm asking because apparently the hw engineers had a reason to make the behavior configurable.
Quoted 12 lines
Fixes f1bce4ad2f1c ("r8169: add support for RTL8125")Signed-off-by ChunHao Lin <[email protected]>--- drivers/net/ethernet/realtek/r8169_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/net/ethernet/realtek/r8169_main.c +0
-0
drivers/net/ethernet/realtek/r8169_main.c enum rtl_registers { · line 199
Quoted 4 lines
drivers/net/ethernet/realtek/r8169_main.c +1
-0@@ -196,6 +196,7 @@ enum rtl_registers {/* No threshold before first PCI xfer */ #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)#define RX_EARLY_OFF (1 << 11) +#define RX_PAUSE_SLOT_ON (1 << 11)
Depending on the chip version this bit has different meanings. Therefore it would be good to add a comment that RX_PAUSE_SLOT_ON is specific to RTL8125B.
Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +5
-1#define RXCFG_DMA_SHIFT 8/* Unlimited maximum PCI burst. */ #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)@@ -2305,9 +2306,13 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp) case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_MULTI_EN |RX_DMA_BURST |RX_EARLY_OFF );break ; - case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_63: +case RTL_GIGA_MAC_VER_61 :RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST );break ; +case RTL_GIGA_MAC_VER_63 : +RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST | +RX_PAUSE_SLOT_ON ); +break ;default :RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_DMA_BURST );break ;
Re: [PATCH net 1/2] r8169: enable rtl8125b pause slot
Quoted 11 lines · Heiner Kallweit
Quoted 9 lines · ChunHao Lin
When FIFO reach near full state, device will issue pause frame. If pause slot is enabled(set to 1), in this time, device will issue pause frame once. But if pause slot is disabled(set to 0), device will keep sending pause frames until FIFO reach near empty state.
When pause slot is disabled, if there is no one to handle receive packets (ex. unexpected shutdown), device FIFO will reach near full state and keep sending pause frames. That will impact entire local area network.
The comment is correct but should mention that this is true after a suspend. In other words, when an idle device goes into a lower power state, eventually the NIC will start blasting PAUSE frames on the local network.
I was able to reproduce the problem very easily with a recent Chromebox (not Chromebook) in developer mode running a test image (and v5.10 kernel):
1) ping -f $CHROMEBOX (from workstation on same local network)
2) run "powerd_dbus_suspend" from command line on the $CHROMEBOX
3) ping $ROUTER (wait until ping fails from workstation)
Takes about ~20-30 seconds after step 2 for the local network to stop working. At that point, tcpdump from the workstation is full of PAUSE frames.
I did not check that WOL still works.
The exact patches I used on chromeos-5.10 kernel branch are publicly visible here:
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/5056381
Quoted 9 lines
Quoted 3 lines
In this patch default enable pause slot to prevent this kind of situation.
Can this change have any side effect? I'm asking because apparently the hw engineers had a reason to make the behavior configurable.
Quoted 3 lines
Fixes f1bce4ad2f1c ("r8169: add support for RTL8125")Signed-off-by ChunHao Lin <[email protected]>
(adding my reviewed-by to indicate I think the code is fine... I appreciate Heiner asking for better comments though.)
cheers,
grant
Quoted 36 lines
drivers/net/ethernet/realtek/r8169_main.c enum rtl_registers { · line 199
Quoted 13 lines
--- drivers/net/ethernet/realtek/r8169_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/net/ethernet/realtek/r8169_main.c +1
-0@@ -196,6 +196,7 @@ enum rtl_registers {/* No threshold before first PCI xfer */ #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)#define RX_EARLY_OFF (1 << 11) +#define RX_PAUSE_SLOT_ON (1 << 11)Depending on the chip version this bit has different meanings. Therefore it would be good to add a comment that
RX_PAUSE_SLOT_ONis specific to RTL8125B.Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +5
-1#define RXCFG_DMA_SHIFT 8/* Unlimited maximum PCI burst. */ #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)@@ -2305,9 +2306,13 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp) case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_MULTI_EN |RX_DMA_BURST |RX_EARLY_OFF );break ; - case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_63: +case RTL_GIGA_MAC_VER_61 :RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST );break ; +case RTL_GIGA_MAC_VER_63 : +RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST | +RX_PAUSE_SLOT_ON ); +break ;default :RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_DMA_BURST );break ;
RE: [PATCH net 1/2] r8169: enable rtl8125b pause slot
In reply to Heiner KallweitQuoted 10 lines
Quoted 10 lines
When FIFO reach near full state, device will issue pause frame. If pause slot is enabled(set to 1), in this time, device will issue pause frame once. But if pause slot is disabled(set to 0), device will keep sending pause frames until FIFO reach near empty state.
When pause slot is disabled, if there is no one to handle receive packets (ex. unexpected shutdown), device FIFO will reach near full state and keep sending pause frames. That will impact entire local area network.
Quoted 5 lines
Quoted 3 lines
In this patch default enable pause slot to prevent this kind of situation.
Can this change have any side effect? I'm asking because apparently the hw engineers had a reason to make the behavior configurable.
It should not have any side effect. This setting is also used in Realtek driver.
Quoted 7 lines
Quoted 7 lines
Fixes f1bce4ad2f1c ("r8169: add support for RTL8125")Signed-off-by ChunHao Lin <[email protected]>--- drivers/net/ethernet/realtek/r8169_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 14 lines
drivers/net/ethernet/realtek/r8169_main.c enum rtl_registers { · line 199
Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +1
-0@@ -196,6 +196,7 @@ enum rtl_registers {/* No threshold before first PCI xfer */ #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)#define RX_EARLY_OFF (1 << 11) +#define RX_PAUSE_SLOT_ON (1 << 11)Depending on the chip version this bit has different meanings. Therefore it would be good to add a comment that
RX_PAUSE_SLOT_ONis specific to RTL8125B.
I will do that and submit again.
Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_rxcfg(struct rtl8169_private
Quoted 4 lines
drivers/net/ethernet/realtek/r8169_main.c +0
-0#define RXCFG_DMA_SHIFT 8/* Unlimited maximum PCI burst. */ #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)@@ -2305,9 +2306,13 @@ static void rtl_init_rxcfg(struct rtl8169_private*tp)
drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_rxcfg(struct rtl8169_private · line 2307
Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0
-0case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53: RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN |
RX_DMA_BURST|RX_EARLY_OFF);Quoted 12 lines
drivers/net/ethernet/realtek/r8169_main.c +5
-1break ; - case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_63: +case RTL_GIGA_MAC_VER_61 :RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST );break ; +case RTL_GIGA_MAC_VER_63 : +RTL_W32 (tp, RxConfig,RX_FETCH_DFLT_8125 |RX_DMA_BURST | +RX_PAUSE_SLOT_ON ); +break ;default :RTL_W32 (tp, RxConfig,RX128_INT_EN |RX_DMA_BURST );break ;
PATCH 2/2 r8169: fix deadlock in "r8169_phylink_handler"
In reply to ChunHao LinIn "r8169_phylink_handler", for rtl8125, it will call "rtl_reset_work"-> "rtl_hw_start"->"rtl_jumbo_config"->"phy_start_aneg". When call "r8169_phylink_handler", PHY lock is acquired. But "phy_start_aneg" will also try to acquire PHY lock. That will cause deadlock.
In this path, use "_phy_start_aneg", unlocked version "phy_start_aneg", to prevent deadlock in "r8169_phylink_handler".
--- drivers/net/ethernet/realtek/r8169_main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +12 -1
@@ -2415,11 +2415,22 @@ static void rtl_jumbo_config(struct rtl8169_private *tp)/* Chip doesn't support pause in jumbo mode */ if (jumbo) { +int lock; +linkmode_clear_bit (ETHTOOL_LINK_MODE_Pause_BIT, tp->phydev->advertising);linkmode_clear_bit (ETHTOOL_LINK_MODE_Asym_Pause_BIT, tp->phydev->advertising); -phy_start_aneg (tp->phydev); + +if (!mutex_trylock (&tp->phydev->lock)) + lock =0 ; +else + lock =1 ; + +_phy_start_aneg (tp->phydev); + +if (lock) +mutex_unlock (&tp->phydev->lock); } }
Signature · 1 line
2.39.2
Heiner Kallweit
maintainerRe: [PATCH net 2/2] r8169: fix deadlock in "r8169_phylink_handler"
Quoted 33 lines · ChunHao Lin
In "
r8169_phylink_handler", for rtl8125, it will call "rtl_reset_work"-> "rtl_hw_start"->"rtl_jumbo_config"->"phy_start_aneg". When call "r8169_phylink_handler", PHY lock is acquired. But "phy_start_aneg" will also try to acquire PHY lock. That will cause deadlock.In this path, use "
_phy_start_aneg", unlocked version "phy_start_aneg", to prevent deadlock in "r8169_phylink_handler".Fixes 453a77894efa ("r8169: don't advertise pause in jumbo mode")Signed-off-by ChunHao Lin <[email protected]>--- drivers/net/ethernet/realtek/r8169_main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/net/ethernet/realtek/r8169_main.c +5
-1@@ -2415,11 +2415,22 @@ static void rtl_jumbo_config(struct rtl8169_private *tp)/* Chip doesn't support pause in jumbo mode */ if (jumbo) { +int lock; +linkmode_clear_bit (ETHTOOL_LINK_MODE_Pause_BIT, tp->phydev->advertising);linkmode_clear_bit (ETHTOOL_LINK_MODE_Asym_Pause_BIT, tp->phydev->advertising); -phy_start_aneg (tp->phydev); + +if (!mutex_trylock (&tp->phydev->lock)) + lock =0 ;
drivers/net/ethernet/realtek/r8169_main.c static void rtl_jumbo_config(struct rtl8169_private *tp) · line 2436
Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +7
-0+else + lock =1 ; + +_phy_start_aneg (tp->phydev); + +if (lock) +mutex_unlock (&tp->phydev->lock); } }
Hi Hau,
the deadlock issue has been reported by few users, and I submitted a fix already. It's waiting to be applied.