net: altera-tse: Cleanup init sequence
Subsystems (3)
v2 cover net: altera-tse: Cleanup init sequence
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/[email protected]/
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(-)
Signature · 1 line
2.49.0
PATCH v2 1/4 net: altera-tse: Set platform drvdata before registering netdev
We don't have to wait until netdev is registered before setting it as the pdev's drvdata. Move it at netdev alloc time.
--- drivers/net/ethernet/altera/altera_tse_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/altera/altera_tse_main.c +1 -2
@@ -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))
Signature · 1 line
2.49.0
Jakub Kicinski
maintainerRe: [PATCH net-next v2 1/4] net: altera-tse: Set platform drvdata before registering netdev
Quoted 2 lines · 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 🤷️
PATCH v2 2/4 net: altera-tse: Warn on bad revision at probe time
In reply to Maxime ChevallierInstead 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.
--- drivers/net/ethernet/altera/altera_tse.h | 3 --- drivers/net/ethernet/altera/altera_tse_main.c | 12 ++++++------ 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/altera/altera_tse.h +0 -3
@@ -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;
drivers/net/ethernet/altera/altera_tse_main.c +6 -6
@@ -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);
Signature · 1 line
2.49.0
Re: [PATCH net-next v2 2/4] net: altera-tse: Warn on bad revision at probe time
Quoted 8 lines · Maxime Chevallier
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().
Quoted 6 lines
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 <[email protected]>Signed-off-by Maxime Chevallier <[email protected]>
Andrew
PATCH v2 3/4 net: altera-tse: Don't use netdev name for the PCS mdio bus
In reply to Maxime ChevallierThe 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
--- drivers/net/ethernet/altera/altera_tse_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/altera/altera_tse_main.c +1 -1
@@ -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);
Signature · 1 line
2.49.0
PATCH v2 4/4 net: altera-tse: Init PCS and phylink before registering netdev
In reply to Maxime Chevallierregister_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.
--- drivers/net/ethernet/altera/altera_tse_main.c | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/net/ethernet/altera/altera_tse_main.c +20 -20
@@ -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:
Signature · 1 line
2.49.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html