netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence
@ 2025-11-03 10:49 Maxime Chevallier
  2025-11-03 10:49 ` [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev Maxime Chevallier
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Maxime Chevallier @ 2025-11-03 10:49 UTC (permalink / raw)
  To: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King
  Cc: Maxime Chevallier, Simon Horman, Boon Khai Ng,
	Alexis Lothoré, Thomas Petazzoni, netdev, linux-arm-kernel,
	linux-kernel

Hi, this is a V2 for Altera TSE cleanup to make sure everything is
properly intialized before registering the netdev.

When Altera TSE was converted to phylink, the PCS and phylink creation
were added after register_netdev(), which is wrong as this may race
with .ndo_open() once the netdev is registered.

This series makes so that we register the netdev once all resources are
cleanly initialised, that includes PCS and phylink creation as well as a
few other operations such as reading the IP version.

No errors were found in the wild, so this series doesn't target net, but
given that we fix some racy-ness, a point could be made to send that to
net.

This series doesn't introduce functional changes, however the internal
mii_bus for PCS configuration is renamed.

V2:
 - Add Andrew's review tags
 - Change patch 2, to get rid of priv->revision and print the core
   revision at probe time instead of doing it in .ndo_open()

V1: https://lore.kernel.org/netdev/20251030102418.114518-1-maxime.chevallier@bootlin.com/

Maxime Chevallier (4):
  net: altera-tse: Set platform drvdata before registering netdev
  net: altera-tse: Warn on bad revision at probe time
  net: altera-tse: Don't use netdev name for the PCS mdio bus
  net: altera-tse: Init PCS and phylink before registering netdev

 drivers/net/ethernet/altera/altera_tse.h      |  3 --
 drivers/net/ethernet/altera/altera_tse_main.c | 47 +++++++++----------
 2 files changed, 23 insertions(+), 27 deletions(-)

-- 
2.49.0


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

* [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev
  2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
@ 2025-11-03 10:49 ` Maxime Chevallier
  2025-11-05  2:20   ` Jakub Kicinski
  2025-11-03 10:49 ` [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time Maxime Chevallier
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Maxime Chevallier @ 2025-11-03 10:49 UTC (permalink / raw)
  To: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King
  Cc: Maxime Chevallier, Simon Horman, Boon Khai Ng,
	Alexis Lothoré, Thomas Petazzoni, netdev, linux-arm-kernel,
	linux-kernel, Andrew Lunn

We don't have to wait until netdev is registered before setting it as the
pdev's drvdata. Move it at netdev alloc time.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/altera/altera_tse_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 3f6204de9e6b..6ba1249f027d 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1150,6 +1150,7 @@ static int altera_tse_probe(struct platform_device *pdev)
 	}
 
 	SET_NETDEV_DEV(ndev, &pdev->dev);
+	platform_set_drvdata(pdev, ndev);
 
 	priv = netdev_priv(ndev);
 	priv->device = &pdev->dev;
@@ -1394,8 +1395,6 @@ static int altera_tse_probe(struct platform_device *pdev)
 		goto err_register_netdev;
 	}
 
-	platform_set_drvdata(pdev, ndev);
-
 	priv->revision = ioread32(&priv->mac_dev->megacore_revision);
 
 	if (netif_msg_probe(priv))
-- 
2.49.0


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

* [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time
  2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
  2025-11-03 10:49 ` [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev Maxime Chevallier
@ 2025-11-03 10:49 ` Maxime Chevallier
  2025-11-03 13:42   ` Andrew Lunn
  2025-11-03 10:49 ` [PATCH net-next v2 3/4] net: altera-tse: Don't use netdev name for the PCS mdio bus Maxime Chevallier
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Maxime Chevallier @ 2025-11-03 10:49 UTC (permalink / raw)
  To: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King
  Cc: Maxime Chevallier, Simon Horman, Boon Khai Ng,
	Alexis Lothoré, Thomas Petazzoni, netdev, linux-arm-kernel,
	linux-kernel, Andrew Lunn

Instead of reading the core revision at probe time, and print a warning
for an unexecpected version at .ndo_open() time, let's print that
warning directly in .probe().

This allows getting rid of the "revision" private field, and also
prevent a potential race between reading the revision in .probe() after
netdev registration, and accessing that revision in .ndo_open().

By printing the warning after register_netdev(), we are sure that we
have a netdev name, and that we try to print the revision after having
read it from the internal registers.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/altera/altera_tse.h      |  3 ---
 drivers/net/ethernet/altera/altera_tse_main.c | 12 ++++++------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/altera/altera_tse.h b/drivers/net/ethernet/altera/altera_tse.h
index 82f2363a45cd..e5a56bb989da 100644
--- a/drivers/net/ethernet/altera/altera_tse.h
+++ b/drivers/net/ethernet/altera/altera_tse.h
@@ -401,9 +401,6 @@ struct altera_tse_private {
 	/* MAC address space */
 	struct altera_tse_mac __iomem *mac_dev;
 
-	/* TSE Revision */
-	u32	revision;
-
 	/* mSGDMA Rx Dispatcher address space */
 	void __iomem *rx_dma_csr;
 	void __iomem *rx_dma_desc;
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 6ba1249f027d..343c78a493a1 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -892,9 +892,6 @@ static int tse_open(struct net_device *dev)
 		netdev_warn(dev, "device MAC address %pM\n",
 			    dev->dev_addr);
 
-	if ((priv->revision < 0xd00) || (priv->revision > 0xe00))
-		netdev_warn(dev, "TSE revision %x\n", priv->revision);
-
 	spin_lock(&priv->mac_cfg_lock);
 
 	ret = reset_mac(priv);
@@ -1142,6 +1139,7 @@ static int altera_tse_probe(struct platform_device *pdev)
 	struct net_device *ndev;
 	void __iomem *descmap;
 	int ret = -ENODEV;
+	u32 revision;
 
 	ndev = alloc_etherdev(sizeof(struct altera_tse_private));
 	if (!ndev) {
@@ -1395,12 +1393,14 @@ static int altera_tse_probe(struct platform_device *pdev)
 		goto err_register_netdev;
 	}
 
-	priv->revision = ioread32(&priv->mac_dev->megacore_revision);
+	revision = ioread32(&priv->mac_dev->megacore_revision);
+
+	if (revision < 0xd00 || revision > 0xe00)
+		netdev_warn(ndev, "TSE revision %x\n", revision);
 
 	if (netif_msg_probe(priv))
 		dev_info(&pdev->dev, "Altera TSE MAC version %d.%d at 0x%08lx irq %d/%d\n",
-			 (priv->revision >> 8) & 0xff,
-			 priv->revision & 0xff,
+			 (revision >> 8) & 0xff, revision & 0xff,
 			 (unsigned long) control_port->start, priv->rx_irq,
 			 priv->tx_irq);
 
-- 
2.49.0


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

* [PATCH net-next v2 3/4] net: altera-tse: Don't use netdev name for the PCS mdio bus
  2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
  2025-11-03 10:49 ` [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev Maxime Chevallier
  2025-11-03 10:49 ` [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time Maxime Chevallier
@ 2025-11-03 10:49 ` Maxime Chevallier
  2025-11-03 10:49 ` [PATCH net-next v2 4/4] net: altera-tse: Init PCS and phylink before registering netdev Maxime Chevallier
  2025-11-05  2:20 ` [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: Maxime Chevallier @ 2025-11-03 10:49 UTC (permalink / raw)
  To: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King
  Cc: Maxime Chevallier, Simon Horman, Boon Khai Ng,
	Alexis Lothoré, Thomas Petazzoni, netdev, linux-arm-kernel,
	linux-kernel, Andrew Lunn

The PCS mdio bus must be created before registering the net_device. To
do that, we musn't depend on the netdev name to create the mdio bus
name. Let's use the device's name instead.

Note that this changes the bus name in /sys/bus/mdiobus

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/altera/altera_tse_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 343c78a493a1..003df8970998 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1404,7 +1404,7 @@ static int altera_tse_probe(struct platform_device *pdev)
 			 (unsigned long) control_port->start, priv->rx_irq,
 			 priv->tx_irq);
 
-	snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name);
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", dev_name(&pdev->dev));
 	pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
 	if (IS_ERR(pcs_bus)) {
 		ret = PTR_ERR(pcs_bus);
-- 
2.49.0


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

* [PATCH net-next v2 4/4] net: altera-tse: Init PCS and phylink before registering netdev
  2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
                   ` (2 preceding siblings ...)
  2025-11-03 10:49 ` [PATCH net-next v2 3/4] net: altera-tse: Don't use netdev name for the PCS mdio bus Maxime Chevallier
@ 2025-11-03 10:49 ` Maxime Chevallier
  2025-11-05  2:20 ` [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: Maxime Chevallier @ 2025-11-03 10:49 UTC (permalink / raw)
  To: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King
  Cc: Maxime Chevallier, Simon Horman, Boon Khai Ng,
	Alexis Lothoré, Thomas Petazzoni, netdev, linux-arm-kernel,
	linux-kernel, Andrew Lunn

register_netdev() must be done only once all resources are ready, as
they may be used in .ndo_open() immediately upon registration.

Move the lynx PCS and phylink initialisation before registerng the
netdevice. We also remove the call to netif_carrier_off(), as phylink
takes care of that.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/altera/altera_tse_main.c | 40 +++++++++----------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 003df8970998..ca55c5fd11df 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1386,24 +1386,6 @@ static int altera_tse_probe(struct platform_device *pdev)
 	spin_lock_init(&priv->tx_lock);
 	spin_lock_init(&priv->rxdma_irq_lock);
 
-	netif_carrier_off(ndev);
-	ret = register_netdev(ndev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register TSE net device\n");
-		goto err_register_netdev;
-	}
-
-	revision = ioread32(&priv->mac_dev->megacore_revision);
-
-	if (revision < 0xd00 || revision > 0xe00)
-		netdev_warn(ndev, "TSE revision %x\n", revision);
-
-	if (netif_msg_probe(priv))
-		dev_info(&pdev->dev, "Altera TSE MAC version %d.%d at 0x%08lx irq %d/%d\n",
-			 (revision >> 8) & 0xff, revision & 0xff,
-			 (unsigned long) control_port->start, priv->rx_irq,
-			 priv->tx_irq);
-
 	snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", dev_name(&pdev->dev));
 	pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
 	if (IS_ERR(pcs_bus)) {
@@ -1441,12 +1423,30 @@ static int altera_tse_probe(struct platform_device *pdev)
 		goto err_init_phylink;
 	}
 
+	ret = register_netdev(ndev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register TSE net device\n");
+		goto err_register_netdev;
+	}
+
+	revision = ioread32(&priv->mac_dev->megacore_revision);
+
+	if (revision < 0xd00 || revision > 0xe00)
+		netdev_warn(ndev, "TSE revision %x\n", revision);
+
+	if (netif_msg_probe(priv))
+		dev_info(&pdev->dev, "Altera TSE MAC version %d.%d at 0x%08lx irq %d/%d\n",
+			 (revision >> 8) & 0xff, revision & 0xff,
+			 (unsigned long)control_port->start, priv->rx_irq,
+			 priv->tx_irq);
+
 	return 0;
+
+err_register_netdev:
+	phylink_destroy(priv->phylink);
 err_init_phylink:
 	lynx_pcs_destroy(priv->pcs);
 err_init_pcs:
-	unregister_netdev(ndev);
-err_register_netdev:
 	netif_napi_del(&priv->napi);
 	altera_tse_mdio_destroy(ndev);
 err_free_netdev:
-- 
2.49.0


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

* Re: [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time
  2025-11-03 10:49 ` [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time Maxime Chevallier
@ 2025-11-03 13:42   ` Andrew Lunn
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2025-11-03 13:42 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Russell King, Simon Horman, Boon Khai Ng, Alexis Lothoré,
	Thomas Petazzoni, netdev, linux-arm-kernel, linux-kernel

On Mon, Nov 03, 2025 at 11:49:25AM +0100, Maxime Chevallier wrote:
> Instead of reading the core revision at probe time, and print a warning
> for an unexecpected version at .ndo_open() time, let's print that
> warning directly in .probe().
> 
> This allows getting rid of the "revision" private field, and also
> prevent a potential race between reading the revision in .probe() after
> netdev registration, and accessing that revision in .ndo_open().
> 
> By printing the warning after register_netdev(), we are sure that we
> have a netdev name, and that we try to print the revision after having
> read it from the internal registers.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence
  2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
                   ` (3 preceding siblings ...)
  2025-11-03 10:49 ` [PATCH net-next v2 4/4] net: altera-tse: Init PCS and phylink before registering netdev Maxime Chevallier
@ 2025-11-05  2:20 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-05  2:20 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, linux, horms,
	boon.khai.ng, alexis.lothore, thomas.petazzoni, netdev,
	linux-arm-kernel, linux-kernel

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  3 Nov 2025 11:49:23 +0100 you wrote:
> Hi, this is a V2 for Altera TSE cleanup to make sure everything is
> properly intialized before registering the netdev.
> 
> When Altera TSE was converted to phylink, the PCS and phylink creation
> were added after register_netdev(), which is wrong as this may race
> with .ndo_open() once the netdev is registered.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/4] net: altera-tse: Set platform drvdata before registering netdev
    https://git.kernel.org/netdev/net-next/c/687452051886
  - [net-next,v2,2/4] net: altera-tse: Warn on bad revision at probe time
    https://git.kernel.org/netdev/net-next/c/dd2619d38d7e
  - [net-next,v2,3/4] net: altera-tse: Don't use netdev name for the PCS mdio bus
    https://git.kernel.org/netdev/net-next/c/9350ea63fec6
  - [net-next,v2,4/4] net: altera-tse: Init PCS and phylink before registering netdev
    https://git.kernel.org/netdev/net-next/c/055e554b8fff

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

* Re: [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev
  2025-11-03 10:49 ` [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev Maxime Chevallier
@ 2025-11-05  2:20   ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2025-11-05  2:20 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Andrew Lunn, davem, Eric Dumazet, Paolo Abeni, Russell King,
	Simon Horman, Boon Khai Ng, Alexis Lothoré, Thomas Petazzoni,
	netdev, linux-arm-kernel, linux-kernel, Andrew Lunn

On Mon,  3 Nov 2025 11:49:24 +0100 Maxime Chevallier wrote:
> We don't have to wait until netdev is registered before setting it as the
> pdev's drvdata. Move it at netdev alloc time.

FWIW sometimes the late setting of drvdata is done to make sure drvdata
is NULL if we error out but forget to set ret (so probe returns 0 even
tho it failed). But the error paths looks fine here so 🤷️

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

end of thread, other threads:[~2025-11-05  2:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 10:49 [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence Maxime Chevallier
2025-11-03 10:49 ` [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev Maxime Chevallier
2025-11-05  2:20   ` Jakub Kicinski
2025-11-03 10:49 ` [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time Maxime Chevallier
2025-11-03 13:42   ` Andrew Lunn
2025-11-03 10:49 ` [PATCH net-next v2 3/4] net: altera-tse: Don't use netdev name for the PCS mdio bus Maxime Chevallier
2025-11-03 10:49 ` [PATCH net-next v2 4/4] net: altera-tse: Init PCS and phylink before registering netdev Maxime Chevallier
2025-11-05  2:20 ` [PATCH net-next v2 0/4] net: altera-tse: Cleanup init sequence patchwork-bot+netdevbpf

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).