mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/6] net: ravb: Fixes for the ravb driver
@ 2023-11-27  9:04 Claudiu
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Hi,

This series adds some fixes for ravb driver. Patches in this series
were initilly part of series at [1].

Changes since [1]:
- addressed review comments
- added patch 6/6

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

Claudiu Beznea (6):
  net: ravb: Check return value of reset_control_deassert()
  net: ravb: Use pm_runtime_resume_and_get()
  net: ravb: Make write access to CXR35 first before accessing other
    EMAC registers
  net: ravb: Start TX queues after HW initialization succeeded
  net: ravb: Stop DMA in case of failures on ravb_open()
  net: ravb: Keep reverse order of operations in ravb_remove()

 drivers/net/ethernet/renesas/ravb_main.c | 58 ++++++++++++++----------
 1 file changed, 35 insertions(+), 23 deletions(-)

-- 
2.39.2


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

* [PATCH 1/6] net: ravb: Check return value of reset_control_deassert()
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27 11:49   ` Philipp Zabel
                     ` (2 more replies)
  2023-11-27  9:04 ` [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get() Claudiu
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

reset_control_deassert() could return an error. Some devices cannot work
if reset signal de-assert operation fails. To avoid this check the return
code of reset_control_deassert() in ravb_probe() and take proper action.

Fixes: 0d13a1a464a0 ("ravb: Add reset support")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes since [1]:
- added goto label for free_netdev()

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index c70cff80cc99..50c4c79be035 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2645,7 +2645,10 @@ static int ravb_probe(struct platform_device *pdev)
 	ndev->features = info->net_features;
 	ndev->hw_features = info->net_hw_features;
 
-	reset_control_deassert(rstc);
+	error = reset_control_deassert(rstc);
+	if (error)
+		goto out_free_netdev;
+
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_get_sync(&pdev->dev);
 
@@ -2872,11 +2875,11 @@ static int ravb_probe(struct platform_device *pdev)
 out_disable_refclk:
 	clk_disable_unprepare(priv->refclk);
 out_release:
-	free_netdev(ndev);
-
 	pm_runtime_put(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	reset_control_assert(rstc);
+out_free_netdev:
+	free_netdev(ndev);
 	return error;
 }
 
-- 
2.39.2


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

* [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get()
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27 16:47   ` Sergey Shtylyov
  2023-11-27  9:04 ` [PATCH 3/6] net: ravb: Make write access to CXR35 first before accessing other EMAC registers Claudiu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

pm_runtime_get_sync() may return an error. In case it returns with an error
dev->power.usage_count needs to be decremented. pm_runtime_resume_and_get()
takes care of this. Thus use it.

Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes since [1]:
- added goto label for pm_runtime_disable(); with this innecessary
  changes were removed

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 50c4c79be035..cd3474168452 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2650,7 +2650,9 @@ static int ravb_probe(struct platform_device *pdev)
 		goto out_free_netdev;
 
 	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(&pdev->dev);
+	error = pm_runtime_resume_and_get(&pdev->dev);
+	if (error < 0)
+		goto out_runtime_disable;
 
 	if (info->multi_irqs) {
 		if (info->err_mgmt_irqs)
@@ -2876,6 +2878,7 @@ static int ravb_probe(struct platform_device *pdev)
 	clk_disable_unprepare(priv->refclk);
 out_release:
 	pm_runtime_put(&pdev->dev);
+out_runtime_disable:
 	pm_runtime_disable(&pdev->dev);
 	reset_control_assert(rstc);
 out_free_netdev:
-- 
2.39.2


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

* [PATCH 3/6] net: ravb: Make write access to CXR35 first before accessing other EMAC registers
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
  2023-11-27  9:04 ` [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get() Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27  9:04 ` [PATCH 4/6] net: ravb: Start TX queues after HW initialization succeeded Claudiu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Hardware manual of RZ/G3S (and RZ/G2L) specifies the following on the
description of CXR35 register (chapter "PHY interface select register
(CXR35)"): "After release reset, make write-access to this register before
making write-access to other registers (except MDIOMOD). Even if not need
to change the value of this register, make write-access to this register
at least one time. Because RGMII/MII MODE is recognized by accessing this
register".

The setup procedure for EMAC module (chapter "Setup procedure" of RZ/G3S,
RZ/G2L manuals) specifies the E-MAC.CXR35 register is the first EMAC
register that is to be configured.

Note [A] from chapter "PHY interface select register (CXR35)" specifies
the following:
[A] The case which CXR35 SEL_XMII is used for the selection of RGMII/MII
in APB Clock 100 MHz.
(1) To use RGMII interface, Set ‘H’03E8_0000’ to this register.
(2) To use MII interface, Set ‘H’03E8_0002’ to this register.

Take into account these indication.

Fixes: 1089877ada8d ("ravb: Add RZ/G2L MII interface support")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---

Changes since [1]:
- collected Rb tag

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index cd3474168452..2d4f4fb3d16e 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -515,6 +515,15 @@ static void ravb_emac_init_gbeth(struct net_device *ndev)
 {
 	struct ravb_private *priv = netdev_priv(ndev);
 
+	if (priv->phy_interface == PHY_INTERFACE_MODE_MII) {
+		ravb_write(ndev, (1000 << 16) | CXR35_SEL_XMII_MII, CXR35);
+		ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1, 0);
+	} else {
+		ravb_write(ndev, (1000 << 16) | CXR35_SEL_XMII_RGMII, CXR35);
+		ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1,
+			    CXR31_SEL_LINK0);
+	}
+
 	/* Receive frame limit set register */
 	ravb_write(ndev, GBETH_RX_BUFF_MAX + ETH_FCS_LEN, RFLR);
 
@@ -537,14 +546,6 @@ static void ravb_emac_init_gbeth(struct net_device *ndev)
 
 	/* E-MAC interrupt enable register */
 	ravb_write(ndev, ECSIPR_ICDIP, ECSIPR);
-
-	if (priv->phy_interface == PHY_INTERFACE_MODE_MII) {
-		ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1, 0);
-		ravb_write(ndev, (1000 << 16) | CXR35_SEL_XMII_MII, CXR35);
-	} else {
-		ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1,
-			    CXR31_SEL_LINK0);
-	}
 }
 
 static void ravb_emac_init_rcar(struct net_device *ndev)
-- 
2.39.2


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

* [PATCH 4/6] net: ravb: Start TX queues after HW initialization succeeded
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
                   ` (2 preceding siblings ...)
  2023-11-27  9:04 ` [PATCH 3/6] net: ravb: Make write access to CXR35 first before accessing other EMAC registers Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27  9:04 ` [PATCH 5/6] net: ravb: Stop DMA in case of failures on ravb_open() Claudiu
  2023-11-27  9:04 ` [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove() Claudiu
  5 siblings, 0 replies; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

ravb_phy_start() may fail. If that happens, the TX queues will remain
started. Thus, move the netif_tx_start_all_queues() after PHY is
successfully initialized.

Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---

Changes since [1]:
- collected Rb tag

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 2d4f4fb3d16e..f7e62e6c9df9 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1812,13 +1812,13 @@ static int ravb_open(struct net_device *ndev)
 	if (info->gptp)
 		ravb_ptp_init(ndev, priv->pdev);
 
-	netif_tx_start_all_queues(ndev);
-
 	/* PHY control start */
 	error = ravb_phy_start(ndev);
 	if (error)
 		goto out_ptp_stop;
 
+	netif_tx_start_all_queues(ndev);
+
 	return 0;
 
 out_ptp_stop:
-- 
2.39.2


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

* [PATCH 5/6] net: ravb: Stop DMA in case of failures on ravb_open()
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
                   ` (3 preceding siblings ...)
  2023-11-27  9:04 ` [PATCH 4/6] net: ravb: Start TX queues after HW initialization succeeded Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27  9:04 ` [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove() Claudiu
  5 siblings, 0 replies; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

In case ravb_phy_start() returns with error the settings applied in
ravb_dmac_init() are not reverted (e.g. config mode). For this call
ravb_stop_dma() on failure path of ravb_open().

Fixes: a0d2f20650e8 ("Renesas Ethernet AVB PTP clock driver")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---

Changes since [1]:
- s/ravb_dma_init/ravb_dmac_init in commit description
- collected Rb tag

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index f7e62e6c9df9..805720166ef3 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1825,6 +1825,7 @@ static int ravb_open(struct net_device *ndev)
 	/* Stop PTP Clock driver */
 	if (info->gptp)
 		ravb_ptp_stop(ndev);
+	ravb_stop_dma(ndev);
 out_free_irq_mgmta:
 	if (!info->multi_irqs)
 		goto out_free_irq;
-- 
2.39.2


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

* [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove()
  2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
                   ` (4 preceding siblings ...)
  2023-11-27  9:04 ` [PATCH 5/6] net: ravb: Stop DMA in case of failures on ravb_open() Claudiu
@ 2023-11-27  9:04 ` Claudiu
  2023-11-27 17:16   ` Sergey Shtylyov
  5 siblings, 1 reply; 13+ messages in thread
From: Claudiu @ 2023-11-27  9:04 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

On RZ/G3S SMARC Carrier II board having RGMII connections b/w Ethernet
MACs and PHYs it has been discovered that doing unbind/bind for ravb
driver in a loop leads to wrong speed and duplex for Ethernet links and
broken connectivity (the connectivity cannot be restored even with
bringing interface down/up). Before doing unbind/bind the Ethernet
interfaces were configured though systemd. The sh instructions used to
do unbind/bind were:

$ cd /sys/bus/platform/drivers/ravb/
$ while :; do echo 11c30000.ethernet > unbind ; \
  echo 11c30000.ethernet > bind; done

It has been discovered that there is a race b/w IOCTLs initialized by
systemd at the response of success binding and the
"ravb_write(ndev, CCC_OPC_RESET, CCC)" instruction in ravb_remove() as
follows:

1/ as a result of bind success the user space open/configures the
   interfaces tough an IOCTL; the following stack trace has been
   identified on RZ/G3S:

Call trace:
dump_backtrace+0x9c/0x100
show_stack+0x20/0x38
dump_stack_lvl+0x48/0x60
dump_stack+0x18/0x28
ravb_open+0x70/0xa58
__dev_open+0xf4/0x1e8
__dev_change_flags+0x198/0x218
dev_change_flags+0x2c/0x80
devinet_ioctl+0x640/0x708
inet_ioctl+0x1e4/0x200
sock_do_ioctl+0x50/0x108
sock_ioctl+0x240/0x358
__arm64_sys_ioctl+0xb0/0x100
invoke_syscall+0x50/0x128
el0_svc_common.constprop.0+0xc8/0xf0
do_el0_svc+0x24/0x38
el0_svc+0x34/0xb8
el0t_64_sync_handler+0xc0/0xc8
el0t_64_sync+0x190/0x198

2/ this call may execute concurrently with ravb_remove() as the
   unbind/bind operation was executed in a loop
3/ if the operation mode is changed to RESET (though
   ravb_write(ndev, CCC_OPC_RESET, CCC) instruction in ravb_remove())
   while the above ravb_open() is in progress it may lead to MAC
   (or PHY, or MAC-PHY connection, the right point hasn't been identified
   at the moment) to be broken, thus the Ethernet connectivity fails to
   restore.

The simple fix for this is to move ravb_write(ndev, CCC_OPC_RESET, CCC))
after unregister_netdev() to avoid resetting the controller while the
netdev interface is still registered.

To avoid future issues in ravb_remove(), the patch follows the proper order
of operations in ravb_remove(): reverse order compared with ravb_probe().
This avoids described races as the IOCTLs as well as unregister_netdev()
(called now at the beginning of ravb_remove()) calls rtnl_lock() before
continuing and IOCTLs check (though devinet_ioctl()) if device is still
registered just after taking the lock:

int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
{
	// ...

        rtnl_lock();

        ret = -ENODEV;
        dev = __dev_get_by_name(net, ifr->ifr_name);
        if (!dev)
                goto done;

	// ...
done:
        rtnl_unlock();
out:
        return ret;
}

Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes since [1]:
- none; this patch is new

[1] https://lore.kernel.org/all/20231120084606.4083194-1-claudiu.beznea.uj@bp.renesas.com/

 drivers/net/ethernet/renesas/ravb_main.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 805720166ef3..9cad10db59b7 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2894,22 +2894,26 @@ static void ravb_remove(struct platform_device *pdev)
 	struct ravb_private *priv = netdev_priv(ndev);
 	const struct ravb_hw_info *info = priv->info;
 
-	/* Stop PTP Clock driver */
-	if (info->ccc_gac)
-		ravb_ptp_stop(ndev);
-
-	clk_disable_unprepare(priv->gptp_clk);
-	clk_disable_unprepare(priv->refclk);
-
-	/* Set reset mode */
-	ravb_write(ndev, CCC_OPC_RESET, CCC);
 	unregister_netdev(ndev);
 	if (info->nc_queues)
 		netif_napi_del(&priv->napi[RAVB_NC]);
 	netif_napi_del(&priv->napi[RAVB_BE]);
+
 	ravb_mdio_release(priv);
+
+	/* Stop PTP Clock driver */
+	if (info->ccc_gac)
+		ravb_ptp_stop(ndev);
+
 	dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
 			  priv->desc_bat_dma);
+
+	/* Set reset mode */
+	ravb_write(ndev, CCC_OPC_RESET, CCC);
+
+	clk_disable_unprepare(priv->gptp_clk);
+	clk_disable_unprepare(priv->refclk);
+
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	reset_control_assert(priv->rstc);
-- 
2.39.2


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

* Re: [PATCH 1/6] net: ravb: Check return value of reset_control_deassert()
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
@ 2023-11-27 11:49   ` Philipp Zabel
  2023-11-27 16:39   ` Sergey Shtylyov
  2023-11-27 16:39   ` Sergey Shtylyov
  2 siblings, 0 replies; 13+ messages in thread
From: Philipp Zabel @ 2023-11-27 11:49 UTC (permalink / raw)
  To: Claudiu, s.shtylyov, davem, edumazet, kuba, pabeni,
	richardcochran, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas,
	robh, biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

On Mo, 2023-11-27 at 11:04 +0200, Claudiu wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> reset_control_deassert() could return an error. Some devices cannot work
> if reset signal de-assert operation fails. To avoid this check the return
> code of reset_control_deassert() in ravb_probe() and take proper action.
> 
> Fixes: 0d13a1a464a0 ("ravb: Add reset support")
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 1/6] net: ravb: Check return value of reset_control_deassert()
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
  2023-11-27 11:49   ` Philipp Zabel
@ 2023-11-27 16:39   ` Sergey Shtylyov
  2023-11-28  7:19     ` claudiu beznea
  2023-11-27 16:39   ` Sergey Shtylyov
  2 siblings, 1 reply; 13+ messages in thread
From: Sergey Shtylyov @ 2023-11-27 16:39 UTC (permalink / raw)
  To: Claudiu, davem, edumazet, kuba, pabeni, richardcochran, p.zabel,
	yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

On 11/27/23 12:04 PM, Claudiu wrote:

> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> reset_control_deassert() could return an error. Some devices cannot work
> if reset signal de-assert operation fails.

   Well, I think all devices can't work if the reset line is connected at all. :-)

> To avoid this check the return
> code of reset_control_deassert() in ravb_probe() and take proper action.

   I'd also mention moving of the free_nedev() call...

> Fixes: 0d13a1a464a0 ("ravb: Add reset support")
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey

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

* Re: [PATCH 1/6] net: ravb: Check return value of reset_control_deassert()
  2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
  2023-11-27 11:49   ` Philipp Zabel
  2023-11-27 16:39   ` Sergey Shtylyov
@ 2023-11-27 16:39   ` Sergey Shtylyov
  2 siblings, 0 replies; 13+ messages in thread
From: Sergey Shtylyov @ 2023-11-27 16:39 UTC (permalink / raw)
  To: Claudiu, davem, edumazet, kuba, pabeni, richardcochran, p.zabel,
	yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

On 11/27/23 12:04 PM, Claudiu wrote:

> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> reset_control_deassert() could return an error. Some devices cannot work
> if reset signal de-assert operation fails.

   Well, I think all devices can't work if the reset line is connected at all. :-)

> To avoid this check the return
> code of reset_control_deassert() in ravb_probe() and take proper action.

   I'd also mention moving of the free_netdev() call...

> Fixes: 0d13a1a464a0 ("ravb: Add reset support")
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey

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

* Re: [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get()
  2023-11-27  9:04 ` [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get() Claudiu
@ 2023-11-27 16:47   ` Sergey Shtylyov
  0 siblings, 0 replies; 13+ messages in thread
From: Sergey Shtylyov @ 2023-11-27 16:47 UTC (permalink / raw)
  To: Claudiu, davem, edumazet, kuba, pabeni, richardcochran, p.zabel,
	yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

On 11/27/23 12:04 PM, Claudiu wrote:

> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> pm_runtime_get_sync() may return an error. In case it returns with an error
> dev->power.usage_count needs to be decremented. pm_runtime_resume_and_get()
> takes care of this. Thus use it.
> 
> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 50c4c79be035..cd3474168452 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[...]
> @@ -2876,6 +2878,7 @@ static int ravb_probe(struct platform_device *pdev)
>  	clk_disable_unprepare(priv->refclk);
>  out_release:
>  	pm_runtime_put(&pdev->dev);
> +out_runtime_disable:

   I'd suggest a shorter name, like out_rpm_disable...

>  	pm_runtime_disable(&pdev->dev);
>  	reset_control_assert(rstc);
>  out_free_netdev:
> 

[...]

MBR, Sergey

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

* Re: [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove()
  2023-11-27  9:04 ` [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove() Claudiu
@ 2023-11-27 17:16   ` Sergey Shtylyov
  0 siblings, 0 replies; 13+ messages in thread
From: Sergey Shtylyov @ 2023-11-27 17:16 UTC (permalink / raw)
  To: Claudiu, davem, edumazet, kuba, pabeni, richardcochran, p.zabel,
	yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea

On 11/27/23 12:04 PM, Claudiu wrote:

> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> On RZ/G3S SMARC Carrier II board having RGMII connections b/w Ethernet
> MACs and PHYs it has been discovered that doing unbind/bind for ravb
> driver in a loop leads to wrong speed and duplex for Ethernet links and
> broken connectivity (the connectivity cannot be restored even with
> bringing interface down/up). Before doing unbind/bind the Ethernet
> interfaces were configured though systemd. The sh instructions used to
> do unbind/bind were:
> 
> $ cd /sys/bus/platform/drivers/ravb/
> $ while :; do echo 11c30000.ethernet > unbind ; \
>   echo 11c30000.ethernet > bind; done
> 
> It has been discovered that there is a race b/w IOCTLs initialized by
> systemd at the response of success binding and the
> "ravb_write(ndev, CCC_OPC_RESET, CCC)" instruction in ravb_remove() as

   s/instruction/call/, perhaps?

> follows:
> 
> 1/ as a result of bind success the user space open/configures the
>    interfaces tough an IOCTL; the following stack trace has been
>    identified on RZ/G3S:
> 
> Call trace:
> dump_backtrace+0x9c/0x100
> show_stack+0x20/0x38
> dump_stack_lvl+0x48/0x60
> dump_stack+0x18/0x28
> ravb_open+0x70/0xa58
> __dev_open+0xf4/0x1e8
> __dev_change_flags+0x198/0x218
> dev_change_flags+0x2c/0x80
> devinet_ioctl+0x640/0x708
> inet_ioctl+0x1e4/0x200
> sock_do_ioctl+0x50/0x108
> sock_ioctl+0x240/0x358
> __arm64_sys_ioctl+0xb0/0x100
> invoke_syscall+0x50/0x128
> el0_svc_common.constprop.0+0xc8/0xf0
> do_el0_svc+0x24/0x38
> el0_svc+0x34/0xb8
> el0t_64_sync_handler+0xc0/0xc8
> el0t_64_sync+0x190/0x198
> 
> 2/ this call may execute concurrently with ravb_remove() as the
>    unbind/bind operation was executed in a loop
> 3/ if the operation mode is changed to RESET (though

   Through?

>    ravb_write(ndev, CCC_OPC_RESET, CCC) instruction in ravb_remove())

   s/instruction/call/, perhaps?

>    while the above ravb_open() is in progress it may lead to MAC
>    (or PHY, or MAC-PHY connection, the right point hasn't been identified
>    at the moment) to be broken, thus the Ethernet connectivity fails to
>    restore.
> 
> The simple fix for this is to move ravb_write(ndev, CCC_OPC_RESET, CCC))
> after unregister_netdev() to avoid resetting the controller while the
> netdev interface is still registered.
> 
> To avoid future issues in ravb_remove(), the patch follows the proper order
> of operations in ravb_remove(): reverse order compared with ravb_probe().
> This avoids described races as the IOCTLs as well as unregister_netdev()
> (called now at the beginning of ravb_remove()) calls rtnl_lock() before
> continuing and IOCTLs check (though devinet_ioctl()) if device is still
> registered just after taking the lock:
> 
> int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
> {
> 	// ...
> 
>         rtnl_lock();
> 
>         ret = -ENODEV;
>         dev = __dev_get_by_name(net, ifr->ifr_name);
>         if (!dev)
>                 goto done;
> 
> 	// ...
> done:
>         rtnl_unlock();
> out:
>         return ret;
> }
> 
> Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

   Sorry for overlooking this race (and other bugs) when prepping
the driver for upstream!

MBR, Sergey

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

* Re: [PATCH 1/6] net: ravb: Check return value of reset_control_deassert()
  2023-11-27 16:39   ` Sergey Shtylyov
@ 2023-11-28  7:19     ` claudiu beznea
  0 siblings, 0 replies; 13+ messages in thread
From: claudiu beznea @ 2023-11-28  7:19 UTC (permalink / raw)
  To: Sergey Shtylyov, davem, edumazet, kuba, pabeni, richardcochran,
	p.zabel, yoshihiro.shimoda.uh, geert+renesas, wsa+renesas, robh,
	biju.das.jz, prabhakar.mahadev-lad.rj, mitsuhiro.kimura.kc,
	masaru.nagai.vx
  Cc: netdev, linux-renesas-soc, linux-kernel, Claudiu Beznea



On 27.11.2023 18:39, Sergey Shtylyov wrote:
> On 11/27/23 12:04 PM, Claudiu wrote:
> 
>> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>>
>> reset_control_deassert() could return an error. Some devices cannot work
>> if reset signal de-assert operation fails.
> 
>    Well, I think all devices can't work if the reset line is connected at all. :-)

I was thinking at the fact that the de-assert support was added just 2
years ago, while the driver seems to be ~8 years old.

> 
>> To avoid this check the return
>> code of reset_control_deassert() in ravb_probe() and take proper action.
> 
>    I'd also mention moving of the free_nedev() call...

ok

> 
>> Fixes: 0d13a1a464a0 ("ravb: Add reset support")
>> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> 
> [...]
> 
> MBR, Sergey

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

end of thread, other threads:[~2023-11-28  7:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27  9:04 [PATCH 0/6] net: ravb: Fixes for the ravb driver Claudiu
2023-11-27  9:04 ` [PATCH 1/6] net: ravb: Check return value of reset_control_deassert() Claudiu
2023-11-27 11:49   ` Philipp Zabel
2023-11-27 16:39   ` Sergey Shtylyov
2023-11-28  7:19     ` claudiu beznea
2023-11-27 16:39   ` Sergey Shtylyov
2023-11-27  9:04 ` [PATCH 2/6] net: ravb: Use pm_runtime_resume_and_get() Claudiu
2023-11-27 16:47   ` Sergey Shtylyov
2023-11-27  9:04 ` [PATCH 3/6] net: ravb: Make write access to CXR35 first before accessing other EMAC registers Claudiu
2023-11-27  9:04 ` [PATCH 4/6] net: ravb: Start TX queues after HW initialization succeeded Claudiu
2023-11-27  9:04 ` [PATCH 5/6] net: ravb: Stop DMA in case of failures on ravb_open() Claudiu
2023-11-27  9:04 ` [PATCH 6/6] net: ravb: Keep reverse order of operations in ravb_remove() Claudiu
2023-11-27 17:16   ` Sergey Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®