Skip to contentSkip to conversation

net: stmmac: enable MAC after MTL configuring

PATCH In review [email protected] 3 participants 3 messages Oct 21, 2024 – Oct 23, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: enable MAC after MTL configuring

From: "hailong.fan" <[email protected]>

DMA maybe block while ETH is opening, Adjust the enable sequence, put the MAC enable last

For example, ETH is directly connected to the switch,
which never power down and sends broadcast packets at regular intervals. During the process of opening ETH, data may flow into the MTL FIFO, once MAC RX is enabled. and then, MTL will be set, such as FIFO size. Once enable DMA, There is a certain probability that DMA will read incorrect data from MTL FIFO, causing DMA to hang up.
By read DMA_Debug_Status, you can be observed that the RPS remains at a certain value forever. The correct process should be to configure MAC/MTL/DMA before enabling DMA/MAC

---
V0-V1:
1. update commit messages

---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c   |  8 --------
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 12 ------------
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |  6 +++---
 3 files changed, 3 insertions(+), 23 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +0 -8
index 0d185e54e..92448d858 100644
@@ -50,10 +50,6 @@ void dwmac4_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
 
 	value |= DMA_CONTROL_ST;
 	writel(value, ioaddr + DMA_CHAN_TX_CONTROL(dwmac4_addrs, chan));
-
-	value = readl(ioaddr + GMAC_CONFIG);
-	value |= GMAC_CONFIG_TE;
-	writel(value, ioaddr + GMAC_CONFIG);
 }
 
 void dwmac4_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
@@ -77,10 +73,6 @@ void dwmac4_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
 	value |= DMA_CONTROL_SR;
 
 	writel(value, ioaddr + DMA_CHAN_RX_CONTROL(dwmac4_addrs, chan));
-
-	value = readl(ioaddr + GMAC_CONFIG);
-	value |= GMAC_CONFIG_RE;
-	writel(value, ioaddr + GMAC_CONFIG);
 }
 
 void dwmac4_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +0 -12
index 7840bc403..cba12edc1 100644
@@ -288,10 +288,6 @@ static void dwxgmac2_dma_start_tx(struct stmmac_priv *priv,
 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
 	value |= XGMAC_TXST;
 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
-
-	value = readl(ioaddr + XGMAC_TX_CONFIG);
-	value |= XGMAC_CONFIG_TE;
-	writel(value, ioaddr + XGMAC_TX_CONFIG);
 }
 
 static void dwxgmac2_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
@@ -302,10 +298,6 @@ static void dwxgmac2_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
 	value &= ~XGMAC_TXST;
 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
-
-	value = readl(ioaddr + XGMAC_TX_CONFIG);
-	value &= ~XGMAC_CONFIG_TE;
-	writel(value, ioaddr + XGMAC_TX_CONFIG);
 }
 
 static void dwxgmac2_dma_start_rx(struct stmmac_priv *priv,
@@ -316,10 +308,6 @@ static void dwxgmac2_dma_start_rx(struct stmmac_priv *priv,
 	value = readl(ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
 	value |= XGMAC_RXST;
 	writel(value, ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
-
-	value = readl(ioaddr + XGMAC_RX_CONFIG);
-	value |= XGMAC_CONFIG_RE;
-	writel(value, ioaddr + XGMAC_RX_CONFIG);
 }
 
 static void dwxgmac2_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index e21404822..c19ca62a4 100644
@@ -3437,9 +3437,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 		priv->hw->rx_csum = 0;
 	}
 
-	/* Enable the MAC Rx/Tx */
-	stmmac_mac_set(priv, priv->ioaddr, true);
-
 	/* Set the HW DMA mode and the COE */
 	stmmac_dma_operation_mode(priv);
 
@@ -3523,6 +3520,9 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 	/* Start the ball rolling... */
 	stmmac_start_all_dma(priv);
 
+	/* Enable the MAC Rx/Tx */
+	stmmac_mac_set(priv, priv->ioaddr, true);
+
 	stmmac_set_hw_vlan_mode(priv, priv->hw);
 
 	return 0;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 15 lines · On Mon, 21 Oct 2024 09:03:05 +0800, [email protected] wrote:

From: "hailong.fan" <[email protected]>

DMA maybe block while ETH is opening, Adjust the enable sequence, put the MAC enable last

For example, ETH is directly connected to the switch,
which never power down and sends broadcast packets at regular intervals. During the process of opening ETH, data may flow into the MTL FIFO, once MAC RX is enabled. and then, MTL will be set, such as FIFO size. Once enable DMA, There is a certain probability that DMA will read incorrect data from MTL FIFO, causing DMA to hang up.
By read DMA_Debug_Status, you can be observed that the RPS remains at a certain value forever. The correct process should be to configure MAC/MTL/DMA before enabling DMA/MAC

Quoted 2 lines

A Fixes: tag should be added.

Quoted 16 lines

static void dwxgmac2_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -3
index e21404822..c19ca62a4 100644
@@ -3437,9 +3437,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 		priv->hw->rx_csum = 0;
 	}
 
-	/* Enable the MAC Rx/Tx */
-	stmmac_mac_set(priv, priv->ioaddr, true);
-
 	/* Set the HW DMA mode and the COE */
 	stmmac_dma_operation_mode(priv);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) · line 3525

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
@@ -3523,6 +3520,9 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 	/* Start the ball rolling... */
 	stmmac_start_all_dma(priv);
 
+	/* Enable the MAC Rx/Tx */
+	stmmac_mac_set(priv, priv->ioaddr, true);
+

This sequence fix should be applied to stmmac_xdp_open() too.

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) · line 3528

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	stmmac_set_hw_vlan_mode(priv, priv->hw);
 
 	return 0;

It is better to split this patch into individual patches, since you are trying to fix an issue related to several previous commits:
dwmac4, dwxgmac2, stmmac_hw_setup() and stmmac_xdp_open()

reviewer
#2 lore raw
Quoted 17 lines · Furong Xu
Quoted 15 lines · On Mon, 21 Oct 2024 09:03:05 +0800, [email protected] wrote:

From: "hailong.fan" <[email protected]>

DMA maybe block while ETH is opening, Adjust the enable sequence, put the MAC enable last

For example, ETH is directly connected to the switch,
which never power down and sends broadcast packets at regular intervals. During the process of opening ETH, data may flow into the MTL FIFO, once MAC RX is enabled. and then, MTL will be set, such as FIFO size. Once enable DMA, There is a certain probability that DMA will read incorrect data from MTL FIFO, causing DMA to hang up.
By read DMA_Debug_Status, you can be observed that the RPS remains at a certain value forever. The correct process should be to configure MAC/MTL/DMA before enabling DMA/MAC

Quoted 4 lines
Quoted 2 lines

A Fixes: tag should be added.

Also, as this patch is a fix for net, that target should be noted in the subject.

Subject: [PATCH v2 net] ...

Please address this and the issues raised by Furong Xu and post a v3.

Quoted 25 lines
Quoted 16 lines

static void dwxgmac2_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -3
index e21404822..c19ca62a4 100644
@@ -3437,9 +3437,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 		priv->hw->rx_csum = 0;
 	}
 
-	/* Enable the MAC Rx/Tx */
-	stmmac_mac_set(priv, priv->ioaddr, true);
-
 	/* Set the HW DMA mode and the COE */
 	stmmac_dma_operation_mode(priv);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) · line 3525

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
@@ -3523,6 +3520,9 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
 	/* Start the ball rolling... */
 	stmmac_start_all_dma(priv);
 
+	/* Enable the MAC Rx/Tx */
+	stmmac_mac_set(priv, priv->ioaddr, true);
+

This sequence fix should be applied to stmmac_xdp_open() too.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) · line 3528

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	stmmac_set_hw_vlan_mode(priv, priv->hw);
 
 	return 0;

It is better to split this patch into individual patches, since you are trying to fix an issue related to several previous commits:
dwmac4, dwxgmac2, stmmac_hw_setup() and stmmac_xdp_open()

And each patch should have an appropriate Fixes tag.

Signature · 1 line
pw-bot: changes-requested