linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] Refine stmmac code
@ 2025-07-22  6:27 Tiezhu Yang
  2025-07-22  6:27 ` [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset() Tiezhu Yang
  2025-07-22  6:27 ` [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Tiezhu Yang
  0 siblings, 2 replies; 8+ messages in thread
From: Tiezhu Yang @ 2025-07-22  6:27 UTC (permalink / raw)
  To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel

Here are two small patches to refine stmmac code when debugging and
testing the problem "Failed to reset the dma".

Tiezhu Yang (2):
  net: stmmac: Return early if invalid in loongson_dwmac_fix_reset()
  net: stmmac: Check stmmac_hw_setup() in stmmac_resume()

 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 +++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset()
  2025-07-22  6:27 [PATCH net-next 0/2] Refine stmmac code Tiezhu Yang
@ 2025-07-22  6:27 ` Tiezhu Yang
  2025-07-22 12:48   ` Maxime Chevallier
  2025-07-22  6:27 ` [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Tiezhu Yang
  1 sibling, 1 reply; 8+ messages in thread
From: Tiezhu Yang @ 2025-07-22  6:27 UTC (permalink / raw)
  To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel

If the DMA_BUS_MODE_SFT_RESET bit is 1 before software reset,
there is no need to do anything for this abnormal case, just
return -EINVAL immediately in loongson_dwmac_fix_reset().

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index e1591e6217d4..6d10077666c7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -513,6 +513,9 @@ static int loongson_dwmac_fix_reset(void *priv, void __iomem *ioaddr)
 {
 	u32 value = readl(ioaddr + DMA_BUS_MODE);
 
+	if (value & DMA_BUS_MODE_SFT_RESET)
+		return -EINVAL;
+
 	value |= DMA_BUS_MODE_SFT_RESET;
 	writel(value, ioaddr + DMA_BUS_MODE);
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume()
  2025-07-22  6:27 [PATCH net-next 0/2] Refine stmmac code Tiezhu Yang
  2025-07-22  6:27 ` [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset() Tiezhu Yang
@ 2025-07-22  6:27 ` Tiezhu Yang
  2025-07-22 12:44   ` Maxime Chevallier
  2025-07-23  7:57   ` Huacai Chen
  1 sibling, 2 replies; 8+ messages in thread
From: Tiezhu Yang @ 2025-07-22  6:27 UTC (permalink / raw)
  To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel

stmmac_hw_setup() may return 0 on success and an appropriate negative
integer as defined in errno.h file on failure, just check it and then
return early if failed in stmmac_resume().

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b948df1bff9a..2bfacab71ab9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7975,7 +7975,14 @@ int stmmac_resume(struct device *dev)
 	stmmac_free_tx_skbufs(priv);
 	stmmac_clear_descriptors(priv, &priv->dma_conf);
 
-	stmmac_hw_setup(ndev, false);
+	ret = stmmac_hw_setup(ndev, false);
+	if (ret < 0) {
+		netdev_err(priv->dev, "%s: Hw setup failed\n", __func__);
+		mutex_unlock(&priv->lock);
+		rtnl_unlock();
+		return ret;
+	}
+
 	stmmac_init_coalesce(priv);
 	phylink_rx_clk_stop_block(priv->phylink);
 	stmmac_set_rx_mode(ndev);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume()
  2025-07-22  6:27 ` [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Tiezhu Yang
@ 2025-07-22 12:44   ` Maxime Chevallier
  2025-07-23  7:57   ` Huacai Chen
  1 sibling, 0 replies; 8+ messages in thread
From: Maxime Chevallier @ 2025-07-22 12:44 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Tue, 22 Jul 2025 14:27:16 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:

> stmmac_hw_setup() may return 0 on success and an appropriate negative
> integer as defined in errno.h file on failure, just check it and then
> return early if failed in stmmac_resume().
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset()
  2025-07-22  6:27 ` [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset() Tiezhu Yang
@ 2025-07-22 12:48   ` Maxime Chevallier
  2025-07-22 13:10     ` Tiezhu Yang
  0 siblings, 1 reply; 8+ messages in thread
From: Maxime Chevallier @ 2025-07-22 12:48 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Tue, 22 Jul 2025 14:27:15 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:

> If the DMA_BUS_MODE_SFT_RESET bit is 1 before software reset,
> there is no need to do anything for this abnormal case, just
> return -EINVAL immediately in loongson_dwmac_fix_reset().
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Do you know when that could ever happen ? I'm asking because this logic
for the DMA reset is duplicated in several places in this driver, maybe
this could be useful for other users as well. I'm guessing this is to
avoid waiting for the timeout when the DMA reset fails, but that is
usually when there's a missing clock somewhere (such as the RGMII clock
from the PHY), in which case I don't think the RST bit will be set.

Maxime

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset()
  2025-07-22 12:48   ` Maxime Chevallier
@ 2025-07-22 13:10     ` Tiezhu Yang
  2025-07-23  9:42       ` Tiezhu Yang
  0 siblings, 1 reply; 8+ messages in thread
From: Tiezhu Yang @ 2025-07-22 13:10 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On 2025/7/22 下午8:48, Maxime Chevallier wrote:
> On Tue, 22 Jul 2025 14:27:15 +0800
> Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> 
>> If the DMA_BUS_MODE_SFT_RESET bit is 1 before software reset,
>> there is no need to do anything for this abnormal case, just
>> return -EINVAL immediately in loongson_dwmac_fix_reset().
>>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> 
> Do you know when that could ever happen ? I'm asking because this logic
> for the DMA reset is duplicated in several places in this driver, maybe
> this could be useful for other users as well. I'm guessing this is to
> avoid waiting for the timeout when the DMA reset fails, but that is
> usually when there's a missing clock somewhere (such as the RGMII clock
> from the PHY), in which case I don't think the RST bit will be set.

To be honest, I am not quite sure the root cause but this actually
happened on the test environment, I guess there is a missing clock.

You are right, the initial aim of this patch is to return early for
this case to avoid waiting for the timeout when the DMA reset fails.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume()
  2025-07-22  6:27 ` [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Tiezhu Yang
  2025-07-22 12:44   ` Maxime Chevallier
@ 2025-07-23  7:57   ` Huacai Chen
  1 sibling, 0 replies; 8+ messages in thread
From: Huacai Chen @ 2025-07-23  7:57 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Tue, Jul 22, 2025 at 2:27 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> stmmac_hw_setup() may return 0 on success and an appropriate negative
> integer as defined in errno.h file on failure, just check it and then
> return early if failed in stmmac_resume().
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index b948df1bff9a..2bfacab71ab9 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -7975,7 +7975,14 @@ int stmmac_resume(struct device *dev)
>         stmmac_free_tx_skbufs(priv);
>         stmmac_clear_descriptors(priv, &priv->dma_conf);
>
> -       stmmac_hw_setup(ndev, false);
> +       ret = stmmac_hw_setup(ndev, false);
> +       if (ret < 0) {
> +               netdev_err(priv->dev, "%s: Hw setup failed\n", __func__);
> +               mutex_unlock(&priv->lock);
> +               rtnl_unlock();
> +               return ret;
> +       }
> +
>         stmmac_init_coalesce(priv);
>         phylink_rx_clk_stop_block(priv->phylink);
>         stmmac_set_rx_mode(ndev);
> --
> 2.42.0
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset()
  2025-07-22 13:10     ` Tiezhu Yang
@ 2025-07-23  9:42       ` Tiezhu Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Tiezhu Yang @ 2025-07-23  9:42 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On 2025/7/22 下午9:10, Tiezhu Yang wrote:
> On 2025/7/22 下午8:48, Maxime Chevallier wrote:
>> On Tue, 22 Jul 2025 14:27:15 +0800
>> Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>>> If the DMA_BUS_MODE_SFT_RESET bit is 1 before software reset,
>>> there is no need to do anything for this abnormal case, just
>>> return -EINVAL immediately in loongson_dwmac_fix_reset().
>>>
>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>
>> Do you know when that could ever happen ? I'm asking because this logic
>> for the DMA reset is duplicated in several places in this driver, maybe
>> this could be useful for other users as well. I'm guessing this is to
>> avoid waiting for the timeout when the DMA reset fails, but that is
>> usually when there's a missing clock somewhere (such as the RGMII clock
>> from the PHY), in which case I don't think the RST bit will be set.
> 
> To be honest, I am not quite sure the root cause but this actually
> happened on the test environment, I guess there is a missing clock.
> 
> You are right, the initial aim of this patch is to return early for
> this case to avoid waiting for the timeout when the DMA reset fails.

With the help of hardware engineer to analysis the ‌device‌ of mainboard,
the root cause is that the MAC controller does not connect to any PHY
interface, there is a missing clock, so the DMA reset fails.

I will send v2 later to update the commit message if it makes sense.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-23  9:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-22  6:27 [PATCH net-next 0/2] Refine stmmac code Tiezhu Yang
2025-07-22  6:27 ` [PATCH net-next 1/2] net: stmmac: Return early if invalid in loongson_dwmac_fix_reset() Tiezhu Yang
2025-07-22 12:48   ` Maxime Chevallier
2025-07-22 13:10     ` Tiezhu Yang
2025-07-23  9:42       ` Tiezhu Yang
2025-07-22  6:27 ` [PATCH net-next 2/2] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Tiezhu Yang
2025-07-22 12:44   ` Maxime Chevallier
2025-07-23  7:57   ` Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).