Skip to contentSkip to conversation

net: stmmac: Set MAC's flow control register to reflect current settings

PATCH Superseded Goh, Wei Sheng 2 participants 2 messages Nov 23, 2022

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: stmmac: Set MAC's flow control register to reflect current settings

Currently, pause frame register GMAC_RX_FLOW_CTRL_RFE is not updated correctly when 'ethtool -A <IFACE> autoneg off rx off tx off' command is issued. This fix ensures the flow control change is reflected directly in the GMAC_RX_FLOW_CTRL_RFE register.

Fixes 46f69ded988d ("net: stmmac: Use resolved link config in mac_link_up()")
Cc <[email protected]> # 5.10.x

---
V2 -> V3: Removed value assign for 'flow' in else statement based on review comments V1 -> V2: Removed needless condition based on review comments

 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c |  2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +2 -0
index c25bfecb4a2d..369db308b1dd 100644
@@ -748,6 +748,8 @@ static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
 	if (fc & FLOW_RX) {
 		pr_debug("\tReceive Flow-Control ON\n");
 		flow |= GMAC_RX_FLOW_CTRL_RFE;
+	} else {
+		pr_debug("\tReceive Flow-Control OFF\n");
 	}
 	writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +10 -2
index 8273e6a175c8..ab7f48f32f5b 100644
@@ -1061,8 +1061,16 @@ static void stmmac_mac_link_up(struct phylink_config *config,
 		ctrl |= priv->hw->link.duplex;
 
 	/* Flow Control operation */
-	if (tx_pause && rx_pause)
-		stmmac_mac_flow_ctrl(priv, duplex);
+	if (rx_pause && tx_pause)
+		priv->flow_ctrl = FLOW_AUTO;
+	else if (rx_pause && !tx_pause)
+		priv->flow_ctrl = FLOW_RX;
+	else if (!rx_pause && tx_pause)
+		priv->flow_ctrl = FLOW_TX;
+	else
+		priv->flow_ctrl = FLOW_OFF;
+
+	stmmac_mac_flow_ctrl(priv, duplex);
 
 	if (ctrl != old_ctrl)
 		writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
Signature · 1 line
2.17.1
#1 lore raw

From: "Goh, Wei Sheng" <[email protected]>
Date: Wed, 23 Nov 2022 17:15:29 +0800

Quoted 23 lines

Currently, pause frame register GMAC_RX_FLOW_CTRL_RFE is not updated correctly when 'ethtool -A <IFACE> autoneg off rx off tx off' command is issued. This fix ensures the flow control change is reflected directly in the GMAC_RX_FLOW_CTRL_RFE register.

Fixes 46f69ded988d ("net: stmmac: Use resolved link config in mac_link_up()")
Cc <[email protected]> # 5.10.x

---
V2 -> V3: Removed value assign for 'flow' in else statement based on review comments V1 -> V2: Removed needless condition based on review comments

 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c |  2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +0 -0
index c25bfecb4a2d..369db308b1dd 100644

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex, · line 752

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +2 -0
@@ -748,6 +748,8 @@ static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
 	if (fc & FLOW_RX) {
 		pr_debug("\tReceive Flow-Control ON\n");
 		flow |= GMAC_RX_FLOW_CTRL_RFE;
+	} else {
+		pr_debug("\tReceive Flow-Control OFF\n");

Doesn't belong the commit subject. Debug improvements usually are -next material.
Also, don't use pr_*() when netdev_*(), pci_*() or dev_*() are available. You won't understand which interface wrote this to the kernel log currently.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +0 -0
 	}
 	writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 8273e6a175c8..ab7f48f32f5b 100644
@@ -1061,8 +1061,16 @@ static void stmmac_mac_link_up(struct phylink_config *config,
 		ctrl |= priv->hw->link.duplex;
 
 	/* Flow Control operation */

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_mac_link_up(struct phylink_config *config, · line 1071

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +8 -2
-	if (tx_pause && rx_pause)
-		stmmac_mac_flow_ctrl(priv, duplex);
+	if (rx_pause && tx_pause)
+		priv->flow_ctrl = FLOW_AUTO;
+	else if (rx_pause && !tx_pause)
+		priv->flow_ctrl = FLOW_RX;
+	else if (!rx_pause && tx_pause)
+		priv->flow_ctrl = FLOW_TX;
+	else
+		priv->flow_ctrl = FLOW_OFF;
	priv->flow_ctrl = FLOW_OFF;
	if (rx_pause)
		priv->flow_ctrl |= FLOW_RX;
	if (tx_pause)
		priv->flow_ctrl |= FLOW_TX;

100% identical functionally.

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
+
+	stmmac_mac_flow_ctrl(priv, duplex);
 
 	if (ctrl != old_ctrl)
 		writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
Signature · 1 line
2.17.1

Thanks,
Olek