* [PATCH net-next v3 1/5] net: stmmac: socfpga: init dwmac->stmmac_rst before registration
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
@ 2025-04-17 17:13 ` Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 2/5] net: stmmac: socfpga: provide init function Russell King (Oracle)
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2025-04-17 17:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Chevallier,
Maxime Coquelin, netdev, Paolo Abeni
Initialisation/setup after registration is a bug. This is the first of
two patches fixing this in socfpga.
dwmac->stmmac_rst is initialised from the stmmac plat_dat's stmmac_rst
member, which is itself initialised by devm_stmmac_probe_config_dt().
Therefore, this can be initialised before we call stmmac_dvr_probe().
Move it there.
dwmac->stmmac_rst is used by the set_phy_mode() method.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index 116855658559..bcdb25ee2a33 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -442,8 +442,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
int ret;
struct socfpga_dwmac *dwmac;
- struct net_device *ndev;
- struct stmmac_priv *stpriv;
const struct socfpga_dwmac_ops *ops;
ops = device_get_match_data(&pdev->dev);
@@ -479,7 +477,13 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
return ret;
}
+ /* The socfpga driver needs to control the stmmac reset to set the phy
+ * mode. Create a copy of the core reset handle so it can be used by
+ * the driver later.
+ */
+ dwmac->stmmac_rst = plat_dat->stmmac_rst;
dwmac->ops = ops;
+
plat_dat->bsp_priv = dwmac;
plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
plat_dat->pcs_init = socfpga_dwmac_pcs_init;
@@ -493,15 +497,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
if (ret)
return ret;
- ndev = platform_get_drvdata(pdev);
- stpriv = netdev_priv(ndev);
-
- /* The socfpga driver needs to control the stmmac reset to set the phy
- * mode. Create a copy of the core reset handle so it can be used by
- * the driver later.
- */
- dwmac->stmmac_rst = stpriv->plat->stmmac_rst;
-
ret = ops->set_phy_mode(dwmac);
if (ret)
goto err_dvr_remove;
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net-next v3 2/5] net: stmmac: socfpga: provide init function
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 1/5] net: stmmac: socfpga: init dwmac->stmmac_rst before registration Russell King (Oracle)
@ 2025-04-17 17:13 ` Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 3/5] net: stmmac: socfpga: convert to stmmac_pltfr_pm_ops Russell King (Oracle)
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2025-04-17 17:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Chevallier,
Maxime Coquelin, netdev, Paolo Abeni
Both the resume and probe path needs to configure the phy mode, so
provide a common function to do this which can later be hooked into
plat_dat->init.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index bcdb25ee2a33..c333ec07d15f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -435,6 +435,13 @@ static struct phylink_pcs *socfpga_dwmac_select_pcs(struct stmmac_priv *priv,
return priv->hw->phylink_pcs;
}
+static int socfpga_dwmac_init(struct platform_device *pdev, void *bsp_priv)
+{
+ struct socfpga_dwmac *dwmac = bsp_priv;
+
+ return dwmac->ops->set_phy_mode(dwmac);
+}
+
static int socfpga_dwmac_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
@@ -497,7 +504,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = ops->set_phy_mode(dwmac);
+ ret = socfpga_dwmac_init(pdev, dwmac);
if (ret)
goto err_dvr_remove;
@@ -512,11 +519,9 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int socfpga_dwmac_resume(struct device *dev)
{
- struct net_device *ndev = dev_get_drvdata(dev);
- struct stmmac_priv *priv = netdev_priv(ndev);
struct socfpga_dwmac *dwmac_priv = get_stmmac_bsp_priv(dev);
- dwmac_priv->ops->set_phy_mode(priv->plat->bsp_priv);
+ socfpga_dwmac_init(to_platform_device(dev), dwmac_priv);
return stmmac_resume(dev);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net-next v3 3/5] net: stmmac: socfpga: convert to stmmac_pltfr_pm_ops
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 1/5] net: stmmac: socfpga: init dwmac->stmmac_rst before registration Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 2/5] net: stmmac: socfpga: provide init function Russell King (Oracle)
@ 2025-04-17 17:13 ` Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 4/5] net: stmmac: socfpga: call set_phy_mode() before registration Russell King (Oracle)
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2025-04-17 17:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Chevallier,
Maxime Coquelin, netdev, Paolo Abeni
Convert socfpga to use the generic stmmac_pltfr_pm_ops, which can be
achieved by adding an appropriate plat_dat->init function to do the
setup.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../ethernet/stmicro/stmmac/dwmac-socfpga.c | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index c333ec07d15f..69ffc52c0275 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -493,6 +493,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
plat_dat->bsp_priv = dwmac;
plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
+ plat_dat->init = socfpga_dwmac_init;
plat_dat->pcs_init = socfpga_dwmac_pcs_init;
plat_dat->pcs_exit = socfpga_dwmac_pcs_exit;
plat_dat->select_pcs = socfpga_dwmac_select_pcs;
@@ -516,40 +517,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
return ret;
}
-#ifdef CONFIG_PM_SLEEP
-static int socfpga_dwmac_resume(struct device *dev)
-{
- struct socfpga_dwmac *dwmac_priv = get_stmmac_bsp_priv(dev);
-
- socfpga_dwmac_init(to_platform_device(dev), dwmac_priv);
-
- return stmmac_resume(dev);
-}
-#endif /* CONFIG_PM_SLEEP */
-
-static int __maybe_unused socfpga_dwmac_runtime_suspend(struct device *dev)
-{
- struct net_device *ndev = dev_get_drvdata(dev);
- struct stmmac_priv *priv = netdev_priv(ndev);
-
- stmmac_bus_clks_config(priv, false);
-
- return 0;
-}
-
-static int __maybe_unused socfpga_dwmac_runtime_resume(struct device *dev)
-{
- struct net_device *ndev = dev_get_drvdata(dev);
- struct stmmac_priv *priv = netdev_priv(ndev);
-
- return stmmac_bus_clks_config(priv, true);
-}
-
-static const struct dev_pm_ops socfpga_dwmac_pm_ops = {
- SET_SYSTEM_SLEEP_PM_OPS(stmmac_suspend, socfpga_dwmac_resume)
- SET_RUNTIME_PM_OPS(socfpga_dwmac_runtime_suspend, socfpga_dwmac_runtime_resume, NULL)
-};
-
static const struct socfpga_dwmac_ops socfpga_gen5_ops = {
.set_phy_mode = socfpga_gen5_set_phy_mode,
};
@@ -570,7 +537,7 @@ static struct platform_driver socfpga_dwmac_driver = {
.remove = stmmac_pltfr_remove,
.driver = {
.name = "socfpga-dwmac",
- .pm = &socfpga_dwmac_pm_ops,
+ .pm = &stmmac_pltfr_pm_ops,
.of_match_table = socfpga_dwmac_match,
},
};
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net-next v3 4/5] net: stmmac: socfpga: call set_phy_mode() before registration
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
` (2 preceding siblings ...)
2025-04-17 17:13 ` [PATCH net-next v3 3/5] net: stmmac: socfpga: convert to stmmac_pltfr_pm_ops Russell King (Oracle)
@ 2025-04-17 17:13 ` Russell King (Oracle)
2025-04-17 17:13 ` [PATCH net-next v3 5/5] net: stmmac: socfpga: convert to devm_stmmac_pltfr_probe() Russell King (Oracle)
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2025-04-17 17:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Chevallier,
Maxime Coquelin, netdev, Paolo Abeni
Initialisation/setup after registration is a bug. This is the second
of two patches fixing this in socfpga.
The set_phy_mode() functions do various hardware setup that would
interfere with a netdev that has been published, and thus available to
be opened by the kernel/userspace.
However, set_phy_mode() relies upon the netdev having been initialised
to get at the plat_stmmacenet_data structure, which is probably why it
was placed after stmmac_drv_probe(). We can remove that need by storing
a pointer to struct plat_stmmacenet_data in struct socfpga_dwmac.
Move the call to set_phy_mode() before calling stmmac_dvr_probe().
This also simplifies the probe function as there is no need to
unregister the netdev if set_phy_mode() fails.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../ethernet/stmicro/stmmac/dwmac-socfpga.c | 20 +++++--------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index 69ffc52c0275..c7c120e30297 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -50,6 +50,7 @@ struct socfpga_dwmac {
u32 reg_offset;
u32 reg_shift;
struct device *dev;
+ struct plat_stmmacenet_data *plat_dat;
struct regmap *sys_mgr_base_addr;
struct reset_control *stmmac_rst;
struct reset_control *stmmac_ocp_rst;
@@ -233,10 +234,7 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
{
- struct net_device *ndev = dev_get_drvdata(dwmac->dev);
- struct stmmac_priv *priv = netdev_priv(ndev);
-
- return priv->plat->mac_interface;
+ return dwmac->plat_dat->mac_interface;
}
static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
@@ -490,6 +488,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
*/
dwmac->stmmac_rst = plat_dat->stmmac_rst;
dwmac->ops = ops;
+ dwmac->plat_dat = plat_dat;
plat_dat->bsp_priv = dwmac;
plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
@@ -501,20 +500,11 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
plat_dat->riwt_off = 1;
- ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
- if (ret)
- return ret;
-
ret = socfpga_dwmac_init(pdev, dwmac);
if (ret)
- goto err_dvr_remove;
-
- return 0;
-
-err_dvr_remove:
- stmmac_dvr_remove(&pdev->dev);
+ return ret;
- return ret;
+ return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
}
static const struct socfpga_dwmac_ops socfpga_gen5_ops = {
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net-next v3 5/5] net: stmmac: socfpga: convert to devm_stmmac_pltfr_probe()
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
` (3 preceding siblings ...)
2025-04-17 17:13 ` [PATCH net-next v3 4/5] net: stmmac: socfpga: call set_phy_mode() before registration Russell King (Oracle)
@ 2025-04-17 17:13 ` Russell King (Oracle)
2025-04-18 9:25 ` [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Maxime Chevallier
2025-04-22 9:10 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2025-04-17 17:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Chevallier,
Maxime Coquelin, netdev, Paolo Abeni
Convert socfpga to use devm_stmmac_pltfr_probe() to further simplify
the probe function, wrapping the call to the set_phy_mode() method
into socfpga_dwmac_init() which can be called from the plat_dat->init()
method. Also call this from socfpga_dwmac_resume() thereby simplifying
that function.
Using the devm variant also means we can remove the call to
stmmac_pltfr_remove().
Unfortunately, we can't also convert to stmmac_pltfr_pm_ops as there is
extra work done in socfpga_dwmac_resume().
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index c7c120e30297..59f90b123c5b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -500,11 +500,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
plat_dat->riwt_off = 1;
- ret = socfpga_dwmac_init(pdev, dwmac);
- if (ret)
- return ret;
-
- return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
+ return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
}
static const struct socfpga_dwmac_ops socfpga_gen5_ops = {
@@ -524,7 +520,6 @@ MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
static struct platform_driver socfpga_dwmac_driver = {
.probe = socfpga_dwmac_probe,
- .remove = stmmac_pltfr_remove,
.driver = {
.name = "socfpga-dwmac",
.pm = &stmmac_pltfr_pm_ops,
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
` (4 preceding siblings ...)
2025-04-17 17:13 ` [PATCH net-next v3 5/5] net: stmmac: socfpga: convert to devm_stmmac_pltfr_probe() Russell King (Oracle)
@ 2025-04-18 9:25 ` Maxime Chevallier
2025-04-22 9:10 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 8+ messages in thread
From: Maxime Chevallier @ 2025-04-18 9:25 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Andrew Lunn, Heiner Kallweit, Alexandre Torgue, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, linux-arm-kernel,
linux-stm32, Maxime Coquelin, netdev, Paolo Abeni
Hi Russell,
On Thu, 17 Apr 2025 18:13:24 +0100
"Russell King (Oracle)" <linux@armlinux.org.uk> wrote:
> Hi,
>
> This series fixes the init ordering of the socfpga probe function.
> The standard rule is to do all setup before publishing any device,
> and socfpga violates that. I can see no reason for this, but these
> patches have not been tested on hardware.
>
> Address this by moving the initialisation of dwmac->stmmac_rst
> along with all the other dwmac initialisers - there's no reason
> for this to be late as plat_dat->stmmac_rst has already been
> populated.
>
> Next, replace the call to ops->set_phy_mode() with an init function
> socfpga_dwmac_init() which will then be linked in to plat_dat->init.
>
> Then, add this to plat_dat->init, and switch to stmmac_pltfr_pm_ops
> from the private ops. The runtime suspend/resume socfpga implementations
> are identical to the platform ones, but misses the noirq versions
> which this will add.
>
> Before we swap the order of socfpga_dwmac_init() and
> stmmac_dvr_probe(), we need to change the way the interface is
> obtained, as that uses driver data and the struct net_device which
> haven't been initialised. Save a pointer to plat_dat in the socfpga
> private data, and use that to get the interface mode. We can then swap
> the order of the init and probe functions.
>
> Finally, convert to devm_stmmac_pltfr_probe() by moving the call
> to ops->set_phy_mode() into an init function appropriately populating
> plat_dat->init.
>
> v2: fix oops when calling set_phy_mode() early.
> v3: fix unused variable warnings in patch 2, add Maxime's r-b and t-b
> to all but patch 2.
Looks like they are missing :)
I re-tested the whole V3 series though and gave a fresh look at your
code, so,
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Thanks !
Maxime
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups
2025-04-17 17:13 [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Russell King (Oracle)
` (5 preceding siblings ...)
2025-04-18 9:25 ` [PATCH net-next v3 0/5] net: stmmac: socfpga: fix init ordering and cleanups Maxime Chevallier
@ 2025-04-22 9:10 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-22 9:10 UTC (permalink / raw)
To: Russell King
Cc: andrew, hkallweit1, alexandre.torgue, andrew+netdev, davem,
edumazet, kuba, linux-arm-kernel, linux-stm32, mcoquelin.stm32,
netdev, pabeni, maxime.chevallier
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 17 Apr 2025 18:13:24 +0100 you wrote:
> Hi,
>
> This series fixes the init ordering of the socfpga probe function.
> The standard rule is to do all setup before publishing any device,
> and socfpga violates that. I can see no reason for this, but these
> patches have not been tested on hardware.
>
> [...]
Here is the summary with links:
- [net-next,v3,1/5] net: stmmac: socfpga: init dwmac->stmmac_rst before registration
https://git.kernel.org/netdev/net-next/c/9276bfc2df92
- [net-next,v3,2/5] net: stmmac: socfpga: provide init function
https://git.kernel.org/netdev/net-next/c/0dbd4a6f57c2
- [net-next,v3,3/5] net: stmmac: socfpga: convert to stmmac_pltfr_pm_ops
https://git.kernel.org/netdev/net-next/c/6bf70d999aa9
- [net-next,v3,4/5] net: stmmac: socfpga: call set_phy_mode() before registration
https://git.kernel.org/netdev/net-next/c/91255347bba9
- [net-next,v3,5/5] net: stmmac: socfpga: convert to devm_stmmac_pltfr_probe()
https://git.kernel.org/netdev/net-next/c/1dbefd578d8b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread