Skip to contentSkip to conversation

net: axienet: Fix deferred probe loop

PATCH In review Sean Anderson 4 participants 21 messages Aug 5, 2025 – Dec 16, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover net: axienet: Fix deferred probe loop

Fix a deferred-probe loop by splitting the MAC and MDIO functionality into separate drivers. Please refer to the last patch for an extended look at the problem this series is attempting to solve.

This is a rather large fix for a rather rare bug, so I have sent it for net-next. The first patch is a smaller fix, however, and could go via net.

Changes in v4:
- Fix documentation for axienet_mdio_enable
- Fix platform_driver_register in exit

Changes in v3:
- Use ioread32/iowrite32 directly in MDIO
- Use MDIO bus device in prints
- Use device variable to probe
- Rework to use a separate axienet_common structure, as netdevs cannot be reused once registered.
- Use ida_alloc for aux id

Changes in v2:
- Fix building as a module
- Expand commit message with much more info on the problem and possible solutions

Sean Anderson (7):
net: axienet: Fix resource release ordering
net: axienet: Use ioread32/iowrite32 directly
net: axienet: Use MDIO bus device in prints
net: axienet: Simplify axienet_mdio_setup
net: axienet: Use device variable in probe
net: axienet: Rearrange lifetime functions
net: axienet: Split into MAC and MDIO drivers

 drivers/net/ethernet/xilinx/Kconfig           |   1 +
 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  45 +-
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 383 +++++++++++-------
 .../net/ethernet/xilinx/xilinx_axienet_mdio.c | 158 ++++----
 4 files changed, 350 insertions(+), 237 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw

PATCH v4 1/7 net: axienet: Fix resource release ordering

Device-managed resources are released after manually-managed resources. Therefore, once any manually-managed resource is acquired, all further resources must be manually-managed too.

Convert all resources before the MDIO bus is created into device-managed resources. In all cases but one there are already devm variants available.

Fixes 46aa27df8853 ("net: axienet: Use devm_* calls")

---

(no changes since v1)

 .../net/ethernet/xilinx/xilinx_axienet_main.c | 89 ++++++++-----------
 1 file changed, 37 insertions(+), 52 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +37 -52
index 6011d7eae0c7..1f277e5e4a62 100644
@@ -2744,6 +2744,11 @@ static void axienet_dma_err_handler(struct work_struct *work)
 	axienet_setoptions(ndev, lp->options);
 }
 
+static void axienet_disable_misc(void *clocks)
+{
+	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, clocks);
+}
+
 /**
  * axienet_probe - Axi Ethernet probe function.
  * @pdev:	Pointer to platform device structure.
@@ -2767,7 +2772,7 @@ static int axienet_probe(struct platform_device *pdev)
 	int addr_width = 32;
 	u32 value;
 
-	ndev = alloc_etherdev(sizeof(*lp));
+	ndev = devm_alloc_etherdev(&pdev->dev, sizeof(*lp));
 	if (!ndev)
 		return -ENOMEM;
 
@@ -2795,22 +2800,17 @@ static int axienet_probe(struct platform_device *pdev)
 	seqcount_mutex_init(&lp->hw_stats_seqcount, &lp->stats_lock);
 	INIT_DEFERRABLE_WORK(&lp->stats_work, axienet_refresh_stats);
 
-	lp->axi_clk = devm_clk_get_optional(&pdev->dev, "s_axi_lite_clk");
+	lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev,
+						    "s_axi_lite_clk");
 	if (!lp->axi_clk) {
 		/* For backward compatibility, if named AXI clock is not present,
 		 * treat the first clock specified as the AXI clock.
 		 */
-		lp->axi_clk = devm_clk_get_optional(&pdev->dev, NULL);
-	}
-	if (IS_ERR(lp->axi_clk)) {
-		ret = PTR_ERR(lp->axi_clk);
-		goto free_netdev;
-	}
-	ret = clk_prepare_enable(lp->axi_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable AXI clock: %d\n", ret);
-		goto free_netdev;
+		lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
 	}
+	if (IS_ERR(lp->axi_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(lp->axi_clk),
+				     "could not get AXI clock\n");
 
 	lp->misc_clks[0].id = "axis_clk";
 	lp->misc_clks[1].id = "ref_clk";
@@ -2818,18 +2818,23 @@ static int axienet_probe(struct platform_device *pdev)
 
 	ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		goto cleanup_clk;
+		return dev_err_probe(&pdev->dev, ret,
+				     "could not get misc. clocks\n");
 
 	ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		goto cleanup_clk;
+		return dev_err_probe(&pdev->dev, ret,
+				     "could not enable misc. clocks\n");
+
+	ret = devm_add_action_or_reset(&pdev->dev, axienet_disable_misc,
+				       lp->misc_clks);
+	if (ret)
+		return ret;
 
 	/* Map device registers */
 	lp->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &ethres);
-	if (IS_ERR(lp->regs)) {
-		ret = PTR_ERR(lp->regs);
-		goto cleanup_clk;
-	}
+	if (IS_ERR(lp->regs))
+		return PTR_ERR(lp->regs);
 	lp->regs_start = ethres->start;
 
 	/* Setup checksum offload, but default to off if not specified */
@@ -2898,19 +2903,17 @@ static int axienet_probe(struct platform_device *pdev)
 			lp->phy_mode = PHY_INTERFACE_MODE_1000BASEX;
 			break;
 		default:
-			ret = -EINVAL;
-			goto cleanup_clk;
+			return -EINVAL;
 		}
 	} else {
 		ret = of_get_phy_mode(pdev->dev.of_node, &lp->phy_mode);
 		if (ret)
-			goto cleanup_clk;
+			return ret;
 	}
 	if (lp->switch_x_sgmii && lp->phy_mode != PHY_INTERFACE_MODE_SGMII &&
 	    lp->phy_mode != PHY_INTERFACE_MODE_1000BASEX) {
 		dev_err(&pdev->dev, "xlnx,switch-x-sgmii only supported with SGMII or 1000BaseX\n");
-		ret = -EINVAL;
-		goto cleanup_clk;
+		return -EINVAL;
 	}
 
 	if (!of_property_present(pdev->dev.of_node, "dmas")) {
@@ -2925,7 +2928,7 @@ static int axienet_probe(struct platform_device *pdev)
 				dev_err(&pdev->dev,
 					"unable to get DMA resource\n");
 				of_node_put(np);
-				goto cleanup_clk;
+				return ret;
 			}
 			lp->dma_regs = devm_ioremap_resource(&pdev->dev,
 							     &dmares);
@@ -2942,19 +2945,17 @@ static int axienet_probe(struct platform_device *pdev)
 		}
 		if (IS_ERR(lp->dma_regs)) {
 			dev_err(&pdev->dev, "could not map DMA regs\n");
-			ret = PTR_ERR(lp->dma_regs);
-			goto cleanup_clk;
+			return PTR_ERR(lp->dma_regs);
 		}
 		if (lp->rx_irq <= 0 || lp->tx_irq <= 0) {
 			dev_err(&pdev->dev, "could not determine irqs\n");
-			ret = -ENOMEM;
-			goto cleanup_clk;
+			return -ENOMEM;
 		}
 
 		/* Reset core now that clocks are enabled, prior to accessing MDIO */
 		ret = __axienet_device_reset(lp);
 		if (ret)
-			goto cleanup_clk;
+			return ret;
 
 		/* Autodetect the need for 64-bit DMA pointers.
 		 * When the IP is configured for a bus width bigger than 32 bits,
@@ -2981,14 +2982,13 @@ static int axienet_probe(struct platform_device *pdev)
 		}
 		if (!IS_ENABLED(CONFIG_64BIT) && lp->features & XAE_FEATURE_DMA_64BIT) {
 			dev_err(&pdev->dev, "64-bit addressable DMA is not compatible with 32-bit architecture\n");
-			ret = -EINVAL;
-			goto cleanup_clk;
+			return -EINVAL;
 		}
 
 		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(addr_width));
 		if (ret) {
 			dev_err(&pdev->dev, "No suitable DMA available\n");
-			goto cleanup_clk;
+			return ret;
 		}
 		netif_napi_add(ndev, &lp->napi_rx, axienet_rx_poll);
 		netif_napi_add(ndev, &lp->napi_tx, axienet_tx_poll);
@@ -2998,15 +2998,12 @@ static int axienet_probe(struct platform_device *pdev)
 
 		lp->eth_irq = platform_get_irq_optional(pdev, 0);
 		if (lp->eth_irq < 0 && lp->eth_irq != -ENXIO) {
-			ret = lp->eth_irq;
-			goto cleanup_clk;
+			return lp->eth_irq;
 		}
 		tx_chan = dma_request_chan(lp->dev, "tx_chan0");
-		if (IS_ERR(tx_chan)) {
-			ret = PTR_ERR(tx_chan);
-			dev_err_probe(lp->dev, ret, "No Ethernet DMA (TX) channel found\n");
-			goto cleanup_clk;
-		}
+		if (IS_ERR(tx_chan))
+			return dev_err_probe(lp->dev, PTR_ERR(tx_chan),
+					     "No Ethernet DMA (TX) channel found\n");
 
 		cfg.reset = 1;
 		/* As name says VDMA but it has support for DMA channel reset */
@@ -3014,7 +3011,7 @@ static int axienet_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(&pdev->dev, "Reset channel failed\n");
 			dma_release_channel(tx_chan);
-			goto cleanup_clk;
+			return ret;
 		}
 
 		dma_release_channel(tx_chan);
@@ -3119,13 +3116,6 @@ static int axienet_probe(struct platform_device *pdev)
 		put_device(&lp->pcs_phy->dev);
 	if (lp->mii_bus)
 		axienet_mdio_teardown(lp);
-cleanup_clk:
-	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
-	clk_disable_unprepare(lp->axi_clk);
-
-free_netdev:
-	free_netdev(ndev);
-
 	return ret;
 }
 
@@ -3143,11 +3133,6 @@ static void axienet_remove(struct platform_device *pdev)
 		put_device(&lp->pcs_phy->dev);
 
 	axienet_mdio_teardown(lp);
-
-	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
-	clk_disable_unprepare(lp->axi_clk);
-
-	free_netdev(ndev);
 }
 
 static void axienet_shutdown(struct platform_device *pdev)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#2 lore raw

Re: [PATCH net-next v4 1/7] net: axienet: Fix resource release ordering

Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -0
+static void axienet_disable_misc(void *clocks)
+{
+	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, clocks);
+}
+

...

Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
 	ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		goto cleanup_clk;
+		return dev_err_probe(&pdev->dev, ret,

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 2830

Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -1
+				     "could not get misc. clocks\n");
 
 	ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		goto cleanup_clk;
+		return dev_err_probe(&pdev->dev, ret,
+				     "could not enable misc. clocks\n");
+
+	ret = devm_add_action_or_reset(&pdev->dev, axienet_disable_misc,
+				       lp->misc_clks);

It seems like it would be better to add devm_clk_bulk_get_optional_enable(). There is already an devm_clk_bulk_get_all_enabled() so it does not seem like too big a step.

Andrew

#3 lore raw

RE: [PATCH net-next v4 1/7] net: axienet: Fix resource release ordering

[Public]

Hi,

Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Wednesday, August 6, 2025 2:29 AM
To: Sean Anderson <[email protected]>
Cc: Pandey, Radhey Shyam <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; linux-arm- [email protected]; [email protected]; Greg Kroah-Hartman <[email protected]>; Simek, Michal <[email protected]>; Leon Romanovsky <[email protected]>; Gupta, Suraj <[email protected]>
Subject: Re: [PATCH net-next v4 1/7] net: axienet: Fix resource release ordering

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines
(quoted diff) +3 -0
+static void axienet_disable_misc(void *clocks) {
+     clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, clocks); }
+

...

Quoted 1 line
      ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS,

lp->misc_clks);

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 2830

Quoted 13 lines

if (ret)

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7 -2
-             goto cleanup_clk;
+             return dev_err_probe(&pdev->dev, ret,
+                                  "could not get misc. clocks\n");
 
      ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
      if (ret)
-             goto cleanup_clk;
+             return dev_err_probe(&pdev->dev, ret,
+                                  "could not enable misc. clocks\n");
+
+     ret = devm_add_action_or_reset(&pdev->dev, axienet_disable_misc,
+                                    lp->misc_clks);
Quoted 5 lines

It seems like it would be better to add devm_clk_bulk_get_optional_enable(). There is already an devm_clk_bulk_get_all_enabled() so it does not seem like too big a step.

Andrew

We are interested in this patch to fix AXI Ethernet probe path and can collaborate on upstreaming it.

Regards,
Suraj

#4 lore raw

Re: [PATCH net-next v4 1/7] net: axienet: Fix resource release ordering

Quoted 42 lines · Suraj

[Public]

Hi,

Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Wednesday, August 6, 2025 2:29 AM
To: Sean Anderson <[email protected]>
Cc: Pandey, Radhey Shyam <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; linux-arm- [email protected]; [email protected]; Greg Kroah-Hartman <[email protected]>; Simek, Michal <[email protected]>; Leon Romanovsky <[email protected]>; Gupta, Suraj <[email protected]>
Subject: Re: [PATCH net-next v4 1/7] net: axienet: Fix resource release ordering

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines
(quoted diff) +3 -0
+static void axienet_disable_misc(void *clocks) {
+     clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, clocks); }
+

...

Quoted 1 line
      ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS,

lp->misc_clks);

Quoted 13 lines

if (ret)

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7 -2
-             goto cleanup_clk;
+             return dev_err_probe(&pdev->dev, ret,
+                                  "could not get misc. clocks\n");
 
      ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
      if (ret)
-             goto cleanup_clk;
+             return dev_err_probe(&pdev->dev, ret,
+                                  "could not enable misc. clocks\n");
+
+     ret = devm_add_action_or_reset(&pdev->dev, axienet_disable_misc,
+                                    lp->misc_clks);
Quoted 7 lines
Quoted 5 lines

It seems like it would be better to add devm_clk_bulk_get_optional_enable(). There is already an devm_clk_bulk_get_all_enabled() so it does not seem like too big a step.

Andrew

We are interested in this patch to fix AXI Ethernet probe path and can collaborate on upstreaming it.

Feel free to modify it as suggested by Andrew.

Unfortunately I have not had time to work on this series recently and probably won't be able to return to it for another few months.

--Sean

#5 lore raw

PATCH v4 2/7 net: axienet: Use ioread32/iowrite32 directly

In reply to Sean Anderson

In preparation for splitting the MDIO bus into a separate driver, convert all register reads/writes to use ioread32/iowrite32 directly instead of using the axienet_ior/iow helpers. While we're at it, clean up the register calculations a bit.

---

(no changes since v3)

Changes in v3:
- New

 .../net/ethernet/xilinx/xilinx_axienet_mdio.c | 43 +++++++++----------
 1 file changed, 20 insertions(+), 23 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +20 -23
index 9ca2643c921e..16f3581390dd 100644
@@ -32,7 +32,7 @@ static int axienet_mdio_wait_until_ready(struct axienet_local *lp)
 {
 	u32 val;
 
-	return readx_poll_timeout(axinet_ior_read_mcr, lp,
+	return readx_poll_timeout(ioread32, lp->regs + XAE_MDIO_MCR_OFFSET,
 				  val, val & XAE_MDIO_MCR_READY_MASK,
 				  1, 20000);
 }
@@ -45,8 +45,8 @@ static int axienet_mdio_wait_until_ready(struct axienet_local *lp)
  */
 static void axienet_mdio_mdc_enable(struct axienet_local *lp)
 {
-	axienet_iow(lp, XAE_MDIO_MC_OFFSET,
-		    ((u32)lp->mii_clk_div | XAE_MDIO_MC_MDIOEN_MASK));
+	iowrite32((u32)lp->mii_clk_div | XAE_MDIO_MC_MDIOEN_MASK,
+		  lp->regs + XAE_MDIO_MC_OFFSET);
 }
 
 /**
@@ -59,9 +59,9 @@ static void axienet_mdio_mdc_disable(struct axienet_local *lp)
 {
 	u32 mc_reg;
 
-	mc_reg = axienet_ior(lp, XAE_MDIO_MC_OFFSET);
-	axienet_iow(lp, XAE_MDIO_MC_OFFSET,
-		    (mc_reg & ~XAE_MDIO_MC_MDIOEN_MASK));
+	mc_reg = ioread32(lp->regs + XAE_MDIO_MC_OFFSET);
+	iowrite32(mc_reg & ~XAE_MDIO_MC_MDIOEN_MASK,
+		  lp->regs + XAE_MDIO_MC_OFFSET);
 }
 
 /**
@@ -90,13 +90,11 @@ static int axienet_mdio_read(struct mii_bus *bus, int phy_id, int reg)
 		return ret;
 	}
 
-	axienet_iow(lp, XAE_MDIO_MCR_OFFSET,
-		    (((phy_id << XAE_MDIO_MCR_PHYAD_SHIFT) &
-		      XAE_MDIO_MCR_PHYAD_MASK) |
-		     ((reg << XAE_MDIO_MCR_REGAD_SHIFT) &
-		      XAE_MDIO_MCR_REGAD_MASK) |
-		     XAE_MDIO_MCR_INITIATE_MASK |
-		     XAE_MDIO_MCR_OP_READ_MASK));
+	rc = FIELD_PREP(XAE_MDIO_MCR_PHYAD_MASK, phy_id) |
+	     FIELD_PREP(XAE_MDIO_MCR_REGAD_MASK, reg) |
+	     XAE_MDIO_MCR_INITIATE_MASK |
+	     XAE_MDIO_MCR_OP_READ_MASK;
+	iowrite32(rc, lp->regs + XAE_MDIO_MCR_OFFSET);
 
 	ret = axienet_mdio_wait_until_ready(lp);
 	if (ret < 0) {
@@ -104,7 +102,7 @@ static int axienet_mdio_read(struct mii_bus *bus, int phy_id, int reg)
 		return ret;
 	}
 
-	rc = axienet_ior(lp, XAE_MDIO_MRD_OFFSET) & 0x0000FFFF;
+	rc = ioread32(lp->regs + XAE_MDIO_MRD_OFFSET) & 0x0000FFFF;
 
 	dev_dbg(lp->dev, "axienet_mdio_read(phy_id=%i, reg=%x) == %x\n",
 		phy_id, reg, rc);
@@ -129,8 +127,9 @@ static int axienet_mdio_read(struct mii_bus *bus, int phy_id, int reg)
 static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
 			      u16 val)
 {
-	int ret;
 	struct axienet_local *lp = bus->priv;
+	int ret;
+	u32 mcr;
 
 	dev_dbg(lp->dev, "axienet_mdio_write(phy_id=%i, reg=%x, val=%x)\n",
 		phy_id, reg, val);
@@ -143,14 +142,12 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
 		return ret;
 	}
 
-	axienet_iow(lp, XAE_MDIO_MWD_OFFSET, (u32)val);
-	axienet_iow(lp, XAE_MDIO_MCR_OFFSET,
-		    (((phy_id << XAE_MDIO_MCR_PHYAD_SHIFT) &
-		      XAE_MDIO_MCR_PHYAD_MASK) |
-		     ((reg << XAE_MDIO_MCR_REGAD_SHIFT) &
-		      XAE_MDIO_MCR_REGAD_MASK) |
-		     XAE_MDIO_MCR_INITIATE_MASK |
-		     XAE_MDIO_MCR_OP_WRITE_MASK));
+	iowrite32(val, lp->regs + XAE_MDIO_MWD_OFFSET);
+	mcr = FIELD_PREP(XAE_MDIO_MCR_PHYAD_MASK, phy_id) |
+	      FIELD_PREP(XAE_MDIO_MCR_REGAD_MASK, reg) |
+	      XAE_MDIO_MCR_INITIATE_MASK |
+	      XAE_MDIO_MCR_OP_WRITE_MASK;
+	iowrite32(mcr, lp->regs + XAE_MDIO_MCR_OFFSET);
 
 	ret = axienet_mdio_wait_until_ready(lp);
 	if (ret < 0) {
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#6 lore raw

Re: [PATCH net-next v4 2/7] net: axienet: Use ioread32/iowrite32 directly

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c static int axienet_mdio_wait_until_ready(struct axienet_local *lp) · line 37

Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +1 -1
-	return readx_poll_timeout(axinet_ior_read_mcr, lp,
+	return readx_poll_timeout(ioread32, lp->regs + XAE_MDIO_MCR_OFFSET,
 				  val, val & XAE_MDIO_MCR_READY_MASK,
 				  1, 20000);

I think this change makes axinet_ior_read_mcr() redundant? So it would be good to remove it.

Andrew

#7 lore raw

PATCH v4 3/7 net: axienet: Use MDIO bus device in prints

In reply to Sean Anderson

For clarity and to remove the dependency on the parent netdev, use the MDIO bus device in print statements.

---

Changes in v4:
- Fix documentation for axienet_mdio_enable

Changes in v3:
- New

 .../net/ethernet/xilinx/xilinx_axienet_mdio.c | 36 ++++++++++---------
 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +20 -16
index 16f3581390dd..dd5f961801dc 100644
@@ -104,7 +104,7 @@ static int axienet_mdio_read(struct mii_bus *bus, int phy_id, int reg)
 
 	rc = ioread32(lp->regs + XAE_MDIO_MRD_OFFSET) & 0x0000FFFF;
 
-	dev_dbg(lp->dev, "axienet_mdio_read(phy_id=%i, reg=%x) == %x\n",
+	dev_dbg(&bus->dev, "%s(phy_id=%i, reg=%x) == %x\n", __func__,
 		phy_id, reg, rc);
 
 	axienet_mdio_mdc_disable(lp);
@@ -131,7 +131,7 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
 	int ret;
 	u32 mcr;
 
-	dev_dbg(lp->dev, "axienet_mdio_write(phy_id=%i, reg=%x, val=%x)\n",
+	dev_dbg(&bus->dev, "%s(phy_id=%i, reg=%x, val=%x)\n", __func__,
 		phy_id, reg, val);
 
 	axienet_mdio_mdc_enable(lp);
@@ -160,7 +160,7 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
 
 /**
  * axienet_mdio_enable - MDIO hardware setup function
- * @lp:		Pointer to axienet local data structure.
+ * @bus:	MDIO bus
  * @np:		Pointer to mdio device tree node.
  *
  * Return:	0 on success, -ETIMEDOUT on a timeout, -EOVERFLOW on a clock
@@ -169,8 +169,9 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
  * Sets up the MDIO interface by initializing the MDIO clock and enabling the
  * MDIO interface in hardware.
  **/
-static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
+static int axienet_mdio_enable(struct mii_bus *bus, struct device_node *np)
 {
+	struct axienet_local *lp = bus->priv;
 	u32 mdio_freq = DEFAULT_MDIO_FREQ;
 	u32 host_clock;
 	u32 clk_div;
@@ -186,28 +187,31 @@ static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
 		/* Legacy fallback: detect CPU clock frequency and use as AXI
 		 * bus clock frequency. This only works on certain platforms.
 		 */
-		np1 = of_find_node_by_name(NULL, "cpu");
+		np1 = of_find_node_by_name(NULL, "lpu");
 		if (!np1) {
-			netdev_warn(lp->ndev, "Could not find CPU device node.\n");
+			dev_warn(&bus->dev,
+				 "Could not find CPU device node.\n");
 			host_clock = DEFAULT_HOST_CLOCK;
 		} else {
 			int ret = of_property_read_u32(np1, "clock-frequency",
 						       &host_clock);
 			if (ret) {
-				netdev_warn(lp->ndev, "CPU clock-frequency property not found.\n");
+				dev_warn(&bus->dev,
+					 "CPU clock-frequency property not found.\n");
 				host_clock = DEFAULT_HOST_CLOCK;
 			}
 			of_node_put(np1);
 		}
-		netdev_info(lp->ndev, "Setting assumed host clock to %u\n",
-			    host_clock);
+		dev_info(&bus->dev,
+			 "Setting assumed host clock to %u\n", host_clock);
 	}
 
 	if (np)
 		of_property_read_u32(np, "clock-frequency", &mdio_freq);
 	if (mdio_freq != DEFAULT_MDIO_FREQ)
-		netdev_info(lp->ndev, "Setting non-standard mdio bus frequency to %u Hz\n",
-			    mdio_freq);
+		dev_info(&bus->dev,
+			 "Setting non-standard mdio bus frequency to %u Hz\n",
+			 mdio_freq);
 
 	/* clk_div can be calculated by deriving it from the equation:
 	 * fMDIO = fHOST / ((1 + clk_div) * 2)
@@ -245,14 +249,14 @@ static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
 
 	/* Check for overflow of mii_clk_div */
 	if (clk_div & ~XAE_MDIO_MC_CLOCK_DIVIDE_MAX) {
-		netdev_warn(lp->ndev, "MDIO clock divisor overflow\n");
+		dev_warn(&bus->dev, "MDIO clock divisor overflow\n");
 		return -EOVERFLOW;
 	}
 	lp->mii_clk_div = (u8)clk_div;
 
-	netdev_dbg(lp->ndev,
-		   "Setting MDIO clock divisor to %u/%u Hz host clock.\n",
-		   lp->mii_clk_div, host_clock);
+	dev_dbg(&bus->dev,
+		"Setting MDIO clock divisor to %u/%u Hz host clock.\n",
+		lp->mii_clk_div, host_clock);
 
 	axienet_mdio_mdc_enable(lp);
 
@@ -295,7 +299,7 @@ int axienet_mdio_setup(struct axienet_local *lp)
 	lp->mii_bus = bus;
 
 	mdio_node = of_get_child_by_name(lp->dev->of_node, "mdio");
-	ret = axienet_mdio_enable(lp, mdio_node);
+	ret = axienet_mdio_enable(bus, mdio_node);
 	if (ret < 0)
 		goto unregister;
 	ret = of_mdiobus_register(bus, mdio_node);
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#8 lore raw

Re: [PATCH net-next v4 3/7] net: axienet: Use MDIO bus device in prints

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np) · line 190

Quoted 9 lines · Sean Anderson

For clarity and to remove the dependency on the parent netdev, use the MDIO bus device in print statements.

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +1 -1
@@ -186,28 +187,31 @@ static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
 		/* Legacy fallback: detect CPU clock frequency and use as AXI
 		 * bus clock frequency. This only works on certain platforms.
 		 */
-		np1 = of_find_node_by_name(NULL, "cpu");
+		np1 = of_find_node_by_name(NULL, "lpu");

There is nothing about dev in this change?

Andrew

#9 lore raw

Re: [PATCH net-next v4 3/7] net: axienet: Use MDIO bus device in prints

Quoted 4 lines · Andrew Lunn
Quoted 2 lines · Sean Anderson

For clarity and to remove the dependency on the parent netdev, use the MDIO bus device in print statements.

Quoted 8 lines

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np) · line 190

Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +1 -1
@@ -186,28 +187,31 @@ static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
 		/* Legacy fallback: detect CPU clock frequency and use as AXI
 		 * bus clock frequency. This only works on certain platforms.
 		 */
-		np1 = of_find_node_by_name(NULL, "cpu");
+		np1 = of_find_node_by_name(NULL, "lpu");

There is nothing about dev in this change?

Whoops, this was left over from doing s/lp/cp/ and then reverting it when I decided that there would be too much diffstat. Will fix for v5.

--Sean

#10 lore raw

PATCH v4 4/7 net: axienet: Simplify axienet_mdio_setup

In reply to Sean Anderson

We always put the mdio_node and disable the bus after probing, so perform these steps unconditionally.

---

(no changes since v1)

 drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +5 -10
index dd5f961801dc..1903a1d50b05 100644
@@ -302,19 +302,14 @@ int axienet_mdio_setup(struct axienet_local *lp)
 	ret = axienet_mdio_enable(bus, mdio_node);
 	if (ret < 0)
 		goto unregister;
+
 	ret = of_mdiobus_register(bus, mdio_node);
-	if (ret)
-		goto unregister_mdio_enabled;
 	of_node_put(mdio_node);
 	axienet_mdio_mdc_disable(lp);
-	return 0;
-
-unregister_mdio_enabled:
-	axienet_mdio_mdc_disable(lp);
-unregister:
-	of_node_put(mdio_node);
-	mdiobus_free(bus);
-	lp->mii_bus = NULL;
+	if (ret) {
+		mdiobus_free(bus);
+		lp->mii_bus = NULL;
+	}
 	return ret;
 }
 
Signature · 1 line
2.35.1.1320.gc452695387.dirty
reviewer
#11 lore raw

Re: [PATCH net-next v4 4/7] net: axienet: Simplify axienet_mdio_setup

Quoted 20 lines · Sean Anderson

We always put the mdio_node and disable the bus after probing, so perform these steps unconditionally.

---

(no changes since v1)

 drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +1 -0
index dd5f961801dc..1903a1d50b05 100644
@@ -302,19 +302,14 @@ int axienet_mdio_setup(struct axienet_local *lp)
 	ret = axienet_mdio_enable(bus, mdio_node);
 	if (ret < 0)
 		goto unregister;
+

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c int axienet_mdio_setup(struct axienet_local *lp) · line 314

Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +0 -7
 	ret = of_mdiobus_register(bus, mdio_node);
-	if (ret)
-		goto unregister_mdio_enabled;
 	of_node_put(mdio_node);
 	axienet_mdio_mdc_disable(lp);
-	return 0;
-
-unregister_mdio_enabled:
-	axienet_mdio_mdc_disable(lp);
-unregister:

Hi Sean,

This function still has code that jumps to unregister. So this causes a compile error.

This does appear to be addressed in patch 6/7.
So I guess it is just an artefact of refactoring the patches or something like that.

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c int axienet_mdio_setup(struct axienet_local *lp) · line 314

Quoted 9 lines
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +4 -3
-	of_node_put(mdio_node);
-	mdiobus_free(bus);
-	lp->mii_bus = NULL;
+	if (ret) {
+		mdiobus_free(bus);
+		lp->mii_bus = NULL;
+	}
 	return ret;
 }

## Form letter - net-next-closed

The merge window for v6.17 has begun and therefore net-next is closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.

Please repost when net-next reopens after 11th August.

RFC patches sent for review only are obviously welcome at any time.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle

Signature · 1 line
pw-bot: defer
#12 lore raw

PATCH v4 5/7 net: axienet: Use device variable in probe

In reply to Sean Anderson

There are a lot of references to pdev->dev that we can shorten by using a dev variable.

---

(no changes since v3)

Changes in v3:
- New

 .../net/ethernet/xilinx/xilinx_axienet_main.c | 83 +++++++++----------
 1 file changed, 41 insertions(+), 42 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +41 -42
index 1f277e5e4a62..28927c7c6c41 100644
@@ -2764,6 +2764,7 @@ static void axienet_disable_misc(void *clocks)
 static int axienet_probe(struct platform_device *pdev)
 {
 	int ret;
+	struct device *dev = &pdev->dev;
 	struct device_node *np;
 	struct axienet_local *lp;
 	struct net_device *ndev;
@@ -2772,13 +2773,13 @@ static int axienet_probe(struct platform_device *pdev)
 	int addr_width = 32;
 	u32 value;
 
-	ndev = devm_alloc_etherdev(&pdev->dev, sizeof(*lp));
+	ndev = devm_alloc_etherdev(dev, sizeof(*lp));
 	if (!ndev)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, ndev);
 
-	SET_NETDEV_DEV(ndev, &pdev->dev);
+	SET_NETDEV_DEV(ndev, dev);
 	ndev->features = NETIF_F_SG;
 	ndev->ethtool_ops = &axienet_ethtool_ops;
 
@@ -2788,7 +2789,7 @@ static int axienet_probe(struct platform_device *pdev)
 
 	lp = netdev_priv(ndev);
 	lp->ndev = ndev;
-	lp->dev = &pdev->dev;
+	lp->dev = dev;
 	lp->options = XAE_OPTION_DEFAULTS;
 	lp->rx_bd_num = RX_BD_NUM_DEFAULT;
 	lp->tx_bd_num = TX_BD_NUM_DEFAULT;
@@ -2800,33 +2801,32 @@ static int axienet_probe(struct platform_device *pdev)
 	seqcount_mutex_init(&lp->hw_stats_seqcount, &lp->stats_lock);
 	INIT_DEFERRABLE_WORK(&lp->stats_work, axienet_refresh_stats);
 
-	lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev,
-						    "s_axi_lite_clk");
+	lp->axi_clk = devm_clk_get_optional_enabled(dev, "s_axi_lite_clk");
 	if (!lp->axi_clk) {
 		/* For backward compatibility, if named AXI clock is not present,
 		 * treat the first clock specified as the AXI clock.
 		 */
-		lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
+		lp->axi_clk = devm_clk_get_optional_enabled(dev, NULL);
 	}
 	if (IS_ERR(lp->axi_clk))
-		return dev_err_probe(&pdev->dev, PTR_ERR(lp->axi_clk),
+		return dev_err_probe(dev, PTR_ERR(lp->axi_clk),
 				     "could not get AXI clock\n");
 
 	lp->misc_clks[0].id = "axis_clk";
 	lp->misc_clks[1].id = "ref_clk";
 	lp->misc_clks[2].id = "mgt_clk";
 
-	ret = devm_clk_bulk_get_optional(&pdev->dev, XAE_NUM_MISC_CLOCKS, lp->misc_clks);
+	ret = devm_clk_bulk_get_optional(dev, XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
+		return dev_err_probe(dev, ret,
 				     "could not get misc. clocks\n");
 
 	ret = clk_bulk_prepare_enable(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
+		return dev_err_probe(dev, ret,
 				     "could not enable misc. clocks\n");
 
-	ret = devm_add_action_or_reset(&pdev->dev, axienet_disable_misc,
+	ret = devm_add_action_or_reset(dev, axienet_disable_misc,
 				       lp->misc_clks);
 	if (ret)
 		return ret;
@@ -2843,7 +2843,7 @@ static int axienet_probe(struct platform_device *pdev)
 	if (axienet_ior(lp, XAE_ABILITY_OFFSET) & XAE_ABILITY_STATS)
 		lp->features |= XAE_FEATURE_STATS;
 
-	ret = of_property_read_u32(pdev->dev.of_node, "xlnx,txcsum", &value);
+	ret = of_property_read_u32(dev->of_node, "xlnx,txcsum", &value);
 	if (!ret) {
 		switch (value) {
 		case 1:
@@ -2858,7 +2858,7 @@ static int axienet_probe(struct platform_device *pdev)
 			break;
 		}
 	}
-	ret = of_property_read_u32(pdev->dev.of_node, "xlnx,rxcsum", &value);
+	ret = of_property_read_u32(dev->of_node, "xlnx,rxcsum", &value);
 	if (!ret) {
 		switch (value) {
 		case 1:
@@ -2877,13 +2877,13 @@ static int axienet_probe(struct platform_device *pdev)
 	 * Here we check for memory allocated for Rx/Tx in the hardware from
 	 * the device-tree and accordingly set flags.
 	 */
-	of_property_read_u32(pdev->dev.of_node, "xlnx,rxmem", &lp->rxmem);
+	of_property_read_u32(dev->of_node, "xlnx,rxmem", &lp->rxmem);
 
-	lp->switch_x_sgmii = of_property_read_bool(pdev->dev.of_node,
+	lp->switch_x_sgmii = of_property_read_bool(dev->of_node,
 						   "xlnx,switch-x-sgmii");
 
 	/* Start with the proprietary, and broken phy_type */
-	ret = of_property_read_u32(pdev->dev.of_node, "xlnx,phy-type", &value);
+	ret = of_property_read_u32(dev->of_node, "xlnx,phy-type", &value);
 	if (!ret) {
 		netdev_warn(ndev, "Please upgrade your device tree binary blob to use phy-mode");
 		switch (value) {
@@ -2906,32 +2906,31 @@ static int axienet_probe(struct platform_device *pdev)
 			return -EINVAL;
 		}
 	} else {
-		ret = of_get_phy_mode(pdev->dev.of_node, &lp->phy_mode);
+		ret = of_get_phy_mode(dev->of_node, &lp->phy_mode);
 		if (ret)
 			return ret;
 	}
 	if (lp->switch_x_sgmii && lp->phy_mode != PHY_INTERFACE_MODE_SGMII &&
 	    lp->phy_mode != PHY_INTERFACE_MODE_1000BASEX) {
-		dev_err(&pdev->dev, "xlnx,switch-x-sgmii only supported with SGMII or 1000BaseX\n");
+		dev_err(dev, "xlnx,switch-x-sgmii only supported with SGMII or 1000BaseX\n");
 		return -EINVAL;
 	}
 
-	if (!of_property_present(pdev->dev.of_node, "dmas")) {
+	if (!of_property_present(dev->of_node, "dmas")) {
 		/* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
-		np = of_parse_phandle(pdev->dev.of_node, "axistream-connected", 0);
+		np = of_parse_phandle(dev->of_node, "axistream-connected", 0);
 
 		if (np) {
 			struct resource dmares;
 
 			ret = of_address_to_resource(np, 0, &dmares);
 			if (ret) {
-				dev_err(&pdev->dev,
+				dev_err(dev,
 					"unable to get DMA resource\n");
 				of_node_put(np);
 				return ret;
 			}
-			lp->dma_regs = devm_ioremap_resource(&pdev->dev,
-							     &dmares);
+			lp->dma_regs = devm_ioremap_resource(dev, &dmares);
 			lp->rx_irq = irq_of_parse_and_map(np, 1);
 			lp->tx_irq = irq_of_parse_and_map(np, 0);
 			of_node_put(np);
@@ -2944,11 +2943,11 @@ static int axienet_probe(struct platform_device *pdev)
 			lp->eth_irq = platform_get_irq_optional(pdev, 2);
 		}
 		if (IS_ERR(lp->dma_regs)) {
-			dev_err(&pdev->dev, "could not map DMA regs\n");
+			dev_err(dev, "could not map DMA regs\n");
 			return PTR_ERR(lp->dma_regs);
 		}
 		if (lp->rx_irq <= 0 || lp->tx_irq <= 0) {
-			dev_err(&pdev->dev, "could not determine irqs\n");
+			dev_err(dev, "could not determine irqs\n");
 			return -ENOMEM;
 		}
 
@@ -2974,20 +2973,20 @@ static int axienet_probe(struct platform_device *pdev)
 				if (ioread32(desc) > 0) {
 					lp->features |= XAE_FEATURE_DMA_64BIT;
 					addr_width = 64;
-					dev_info(&pdev->dev,
+					dev_info(dev,
 						 "autodetected 64-bit DMA range\n");
 				}
 				iowrite32(0x0, desc);
 			}
 		}
 		if (!IS_ENABLED(CONFIG_64BIT) && lp->features & XAE_FEATURE_DMA_64BIT) {
-			dev_err(&pdev->dev, "64-bit addressable DMA is not compatible with 32-bit architecture\n");
+			dev_err(dev, "64-bit addressable DMA is not compatible with 32-bit architecture\n");
 			return -EINVAL;
 		}
 
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(addr_width));
+		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(addr_width));
 		if (ret) {
-			dev_err(&pdev->dev, "No suitable DMA available\n");
+			dev_err(dev, "No suitable DMA available\n");
 			return ret;
 		}
 		netif_napi_add(ndev, &lp->napi_rx, axienet_rx_poll);
@@ -3000,16 +2999,16 @@ static int axienet_probe(struct platform_device *pdev)
 		if (lp->eth_irq < 0 && lp->eth_irq != -ENXIO) {
 			return lp->eth_irq;
 		}
-		tx_chan = dma_request_chan(lp->dev, "tx_chan0");
+		tx_chan = dma_request_chan(dev, "tx_chan0");
 		if (IS_ERR(tx_chan))
-			return dev_err_probe(lp->dev, PTR_ERR(tx_chan),
+			return dev_err_probe(dev, PTR_ERR(tx_chan),
 					     "No Ethernet DMA (TX) channel found\n");
 
 		cfg.reset = 1;
 		/* As name says VDMA but it has support for DMA channel reset */
 		ret = xilinx_vdma_channel_set_config(tx_chan, &cfg);
 		if (ret < 0) {
-			dev_err(&pdev->dev, "Reset channel failed\n");
+			dev_err(dev, "Reset channel failed\n");
 			dma_release_channel(tx_chan);
 			return ret;
 		}
@@ -3024,14 +3023,14 @@ static int axienet_probe(struct platform_device *pdev)
 		ndev->netdev_ops = &axienet_netdev_ops;
 	/* Check for Ethernet core IRQ (optional) */
 	if (lp->eth_irq <= 0)
-		dev_info(&pdev->dev, "Ethernet core IRQ not defined\n");
+		dev_info(dev, "Ethernet core IRQ not defined\n");
 
 	/* Retrieve the MAC address */
-	ret = of_get_mac_address(pdev->dev.of_node, mac_addr);
+	ret = of_get_mac_address(dev->of_node, mac_addr);
 	if (!ret) {
 		axienet_set_mac_address(ndev, mac_addr);
 	} else {
-		dev_warn(&pdev->dev, "could not find MAC address property: %d\n",
+		dev_warn(dev, "could not find MAC address property: %d\n",
 			 ret);
 		axienet_set_mac_address(ndev, NULL);
 	}
@@ -3048,21 +3047,21 @@ static int axienet_probe(struct platform_device *pdev)
 
 	ret = axienet_mdio_setup(lp);
 	if (ret)
-		dev_warn(&pdev->dev,
+		dev_warn(dev,
 			 "error registering MDIO bus: %d\n", ret);
 
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
-		np = of_parse_phandle(pdev->dev.of_node, "pcs-handle", 0);
+		np = of_parse_phandle(dev->of_node, "pcs-handle", 0);
 		if (!np) {
 			/* Deprecated: Always use "pcs-handle" for pcs_phy.
 			 * Falling back to "phy-handle" here is only for
 			 * backward compatibility with old device trees.
 			 */
-			np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+			np = of_parse_phandle(dev->of_node, "phy-handle", 0);
 		}
 		if (!np) {
-			dev_err(&pdev->dev, "pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
+			dev_err(dev, "pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
 			ret = -EINVAL;
 			goto cleanup_mdio;
 		}
@@ -3091,18 +3090,18 @@ static int axienet_probe(struct platform_device *pdev)
 			  lp->phylink_config.supported_interfaces);
 	}
 
-	lp->phylink = phylink_create(&lp->phylink_config, pdev->dev.fwnode,
+	lp->phylink = phylink_create(&lp->phylink_config, dev->fwnode,
 				     lp->phy_mode,
 				     &axienet_phylink_ops);
 	if (IS_ERR(lp->phylink)) {
 		ret = PTR_ERR(lp->phylink);
-		dev_err(&pdev->dev, "phylink_create error (%i)\n", ret);
+		dev_err(dev, "phylink_create error (%i)\n", ret);
 		goto cleanup_mdio;
 	}
 
 	ret = register_netdev(lp->ndev);
 	if (ret) {
-		dev_err(lp->dev, "register_netdev() error (%i)\n", ret);
+		dev_err(dev, "register_netdev() error (%i)\n", ret);
 		goto cleanup_phylink;
 	}
 
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#14 lore raw

PATCH v4 6/7 net: axienet: Rearrange lifetime functions

In reply to Sean Anderson

Rearrange the lifetime functions (probe, remove, etc.) in preparation for the next commit. No functional change intended.

---

(no changes since v3)

Changes in v3:
- Rework to use a separate axienet_common structure

 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  41 ++++--
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 135 ++++++++++--------
 .../net/ethernet/xilinx/xilinx_axienet_mdio.c |  43 +++---
 3 files changed, 126 insertions(+), 93 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +28 -13
index 5ff742103beb..d7215dd92ce9 100644
@@ -467,6 +467,29 @@ struct skbuf_dma_descriptor {
 	int sg_len;
 };
 
+/**
+ * struct axienet_common - axienet private common data
+ * @pdev: Pointer to common platform device structure
+ * @axi_clk: AXI4-Lite bus clock
+ * @reset_lock: Lock held while resetting the device to prevent register access
+ * @mii_bus: Pointer to MII bus structure
+ * @mii_clk_div: MII bus clock divider value
+ * @regs_start: Resource start for axienet device addresses
+ * @regs: Base address for the axienet_local device address space
+ */
+struct axienet_common {
+	struct platform_device *pdev;
+
+	struct clk *axi_clk;
+
+	struct mutex reset_lock;
+	struct mii_bus *mii_bus;
+	u8 mii_clk_div;
+
+	void __iomem *regs;
+	resource_size_t regs_start;
+};
+
 /**
  * struct axienet_local - axienet private per device data
  * @ndev:	Pointer for net_device to which it will be attached.
@@ -549,6 +572,7 @@ struct skbuf_dma_descriptor {
 struct axienet_local {
 	struct net_device *ndev;
 	struct device *dev;
+	struct axienet_common *cp;
 
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
@@ -558,13 +582,11 @@ struct axienet_local {
 
 	bool switch_x_sgmii;
 
-	struct clk *axi_clk;
 	struct clk_bulk_data misc_clks[XAE_NUM_MISC_CLOCKS];
 
 	struct mii_bus *mii_bus;
 	u8 mii_clk_div;
 
-	resource_size_t regs_start;
 	void __iomem *regs;
 	void __iomem *dma_regs;
 
@@ -654,21 +676,14 @@ static inline u32 axienet_ior(struct axienet_local *lp, off_t offset)
 	return ioread32(lp->regs + offset);
 }
 
-static inline u32 axinet_ior_read_mcr(struct axienet_local *lp)
-{
-	return axienet_ior(lp, XAE_MDIO_MCR_OFFSET);
-}
-
 static inline void axienet_lock_mii(struct axienet_local *lp)
 {
-	if (lp->mii_bus)
-		mutex_lock(&lp->mii_bus->mdio_lock);
+	mutex_lock(&lp->cp->reset_lock);
 }
 
 static inline void axienet_unlock_mii(struct axienet_local *lp)
 {
-	if (lp->mii_bus)
-		mutex_unlock(&lp->mii_bus->mdio_lock);
+	mutex_unlock(&lp->cp->reset_lock);
 }
 
 /**
@@ -738,7 +753,7 @@ static inline void axienet_dma_out_addr(struct axienet_local *lp, off_t reg,
 #endif /* CONFIG_64BIT */
 
 /* Function prototypes visible in xilinx_axienet_mdio.c for other files */
-int axienet_mdio_setup(struct axienet_local *lp);
-void axienet_mdio_teardown(struct axienet_local *lp);
+int axienet_mdio_setup(struct axienet_common *lp);
+void axienet_mdio_teardown(struct axienet_common *lp);
 
 #endif /* XILINX_AXI_ENET_H */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +73 -62

222 lines not on this page · raw message

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +25 -18

150 lines not on this page · raw message

Signature · 1 line
2.35.1.1320.gc452695387.dirty
reviewer
#15 lore raw

Re: [PATCH net-next v4 6/7] net: axienet: Rearrange lifetime functions

Quoted 4 lines · Sean Anderson

Rearrange the lifetime functions (probe, remove, etc.) in preparation for the next commit. No functional change intended.

...

Quoted 1 line
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -0

...

drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor { · line 575

Quoted 8 lines

/**
* struct axienet_local - axienet private per device data
* @ndev: Pointer for net_device to which it will be attached.

drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
@@ -549,6 +572,7 @@ struct skbuf_dma_descriptor {
 struct axienet_local {
 	struct net_device *ndev;
 	struct device *dev;
+	struct axienet_common *cp;

nit: Please add cp to, and remove axi_clk and regs_start from
the Kernel doc for this structure.

Flagged by ./scripts/kernel-doc -none

Quoted 17 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -2
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
@@ -558,13 +582,11 @@ struct axienet_local {
 
 	bool switch_x_sgmii;
 
-	struct clk *axi_clk;
 	struct clk_bulk_data misc_clks[XAE_NUM_MISC_CLOCKS];
 
 	struct mii_bus *mii_bus;
 	u8 mii_clk_div;
 
-	resource_size_t regs_start;
 	void __iomem *regs;
 	void __iomem *dma_regs;
 

...

#16 lore raw

Re: [PATCH net-next v4 6/7] net: axienet: Rearrange lifetime functions

In reply to Sean Anderson
Quoted 2 lines · Sean Anderson

Rearrange the lifetime functions (probe, remove, etc.) in preparation for the next commit. No functional change intended.

There is a lot going on in this patch. Can it be broken up a bit more?

The phase "No functional change intended" generally means, its the same code, just in a different place in the files. This is not true of this patch.

drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor {

Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +7 -2
+struct axienet_common {
+	struct platform_device *pdev;
+
+	struct clk *axi_clk;
+
+	struct mutex reset_lock;
 
 static inline void axienet_lock_mii(struct axienet_local *lp)
 {
-	if (lp->mii_bus)
-		mutex_lock(&lp->mii_bus->mdio_lock);
+	mutex_lock(&lp->cp->reset_lock);

This lock is different to the bus lock. This is definitely not a "no functional change".

Please make this lock change a patch of its own, with a good commit message which considers the consequences of this change of lock.

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 3034

Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3 -3
 		if (!np) {
-			dev_err(dev, "pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
-			ret = -EINVAL;
-			goto cleanup_mdio;
+			dev_err(dev,
+				"pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
+			return -EINVAL;

That looks like a whitespace change. This is a "No functional change intended" sort of patch. You can collect all such whitespace changes into one patch.

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
 		}
 		lp->pcs_phy = of_mdio_find_device(np);
-		np1 = of_find_node_by_name(NULL, "lpu");
+		np1 = of_find_node_by_name(NULL, "cpu");

Interesting. Maybe you should review your own patches.

Andrew

---
pw-bot: cr

#17 lore raw

Re: [PATCH net-next v4 6/7] net: axienet: Rearrange lifetime functions

Quoted 9 lines · Andrew Lunn
Quoted 2 lines · Sean Anderson

Rearrange the lifetime functions (probe, remove, etc.) in preparation for the next commit. No functional change intended.

There is a lot going on in this patch. Can it be broken up a bit more?

The phase "No functional change intended" generally means, its the same code, just in a different place in the files. This is not true of this patch.

Sorry, at one point that was true and then I made a some edits. I will update the commit message.

Quoted 16 lines

drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor {

Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +7 -2
+struct axienet_common {
+	struct platform_device *pdev;
+
+	struct clk *axi_clk;
+
+	struct mutex reset_lock;
 
 static inline void axienet_lock_mii(struct axienet_local *lp)
 {
-	if (lp->mii_bus)
-		mutex_lock(&lp->mii_bus->mdio_lock);
+	mutex_lock(&lp->cp->reset_lock);

This lock is different to the bus lock. This is definitely not a "no functional change".

Quoted 2 lines

Please make this lock change a patch of its own, with a good commit message which considers the consequences of this change of lock.

OK

Quoted 11 lines

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 3034

Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3 -3
 		if (!np) {
-			dev_err(dev, "pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
-			ret = -EINVAL;
-			goto cleanup_mdio;
+			dev_err(dev,
+				"pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
+			return -EINVAL;

That looks like a whitespace change. This is a "No functional change intended" sort of patch. You can collect all such whitespace changes into one patch.

The main purpose of that hunk is to remove the goto cleanup_mdio. The dev_err change is just because I was "in the area".

Quoted 6 lines

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
 		}
 		lp->pcs_phy = of_mdio_find_device(np);
-		np1 = of_find_node_by_name(NULL, "lpu");
+		np1 = of_find_node_by_name(NULL, "cpu");

Interesting. Maybe you should review your own patches.

Will do.

--Sean

#18 lore raw

PATCH v4 7/7 net: axienet: Split into MAC and MDIO drivers

In reply to Sean Anderson

Returning EPROBE_DEFER after probing a bus may result in an infinite probe loop if the EPROBE_DEFER error is never resolved. There are two mutually-exclusive scenarios (that can both occur in the same system). First, the PCS can be attached to our own MDIO bus:

MAC
|

 +->MDIO
     |
     +->PCS
     +->PHY (etc)

In this scenario, we have to probe the MDIO bus before we can look up the PCS, since otherwise the PCS will always be missing when we look for it. But if we do things in the right order then we can't get EPROBE_DEFER, and so there's no risk of a probe loop.

Second, the PCS can be attached to some other MDIO bus:

MAC MDIO

 |                 |
 +->MDIO           +->PCS
      |
      +->PHY (etc)

In this scenario, the MDIO bus might not be present for whatever reason (module not loaded, error in probe, etc.) and we have the possibility of an EPROBE_DEFER error. If that happens, we will end up in a probe loop because the PHY on our own MDIO bus incremented deferred_trigger_count when it probed successfully:

deferred_probe_work_func()
driver_probe_device(MAC)

    axienet_probe(MAC)
      mdiobus_register(MDIO)
        device_add(PHY)
          (probe successful)
          driver_bound(PHY)
            driver_deferred_probe_trigger()
      return -EPROBE_DEFER
    driver_deferred_probe_add(MAC)
    // deferred_trigger_count changed, so...
    driver_deferred_probe_trigger()

As I see it, this problem could be solved in the following four ways:

- Modify the driver core to detect and mitigate this sort of scenario (NACKed by Greg).
- Split the driver into MAC and MDIO parts (this commit).
- Modify phylink to allow connecting a PCS after phylink_create but before phylink_start. This is tricky because the PCS can affect the supported phy interfaces, and phy interfaces are validated in phylink_create.
- Defer phylink_create to ndo_open. This means that all the netdev/ethtool ops that use phylink now need to check ip the netdev is open and fall back to some other implementation. I don't think we can just return -EINVAL or whatever because using ethtool on a down device has historically worked. I am wary of breaking userspace because some tool assumes it can get_ksettings while the netdev is down.

Aside from the first option, the second one (this commit) has the best UX. With the latter two, you could have a netdev that never comes up and the user may not have very good insight as to why. For example, it may not be obvious that the user should try to bring the netdev up again after the PCS is probed. By waiting to create the netdev until after we successfully probe the PCS we show up in devices_deferred and the netdev can be brought up as usual.

Per the second bullet point above, split the MAC and MDIO functionality into separate auxiliary devices. If the MAC fails with EPROBE_DEFER, then the MDIO bus will remain bound, preventing a probe loop.

Fixes 1a02556086fc ("net: axienet: Properly handle PCS/PMA PHY for 1000BaseX mode")

---

Changes in v4:
- Fix platform_driver_register in exit

Changes in v3:
- Rework to use a separate axienet_common structure, as netdevs cannot be reused once registered.
- Use ida_alloc for aux id

Changes in v2:
- Fix building as a module
- Expand commit message with much more info on the problem and possible solutions

 drivers/net/ethernet/xilinx/Kconfig           |   1 +
 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  10 +-
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 168 ++++++++++++++----
 .../net/ethernet/xilinx/xilinx_axienet_mdio.c |  59 +++---
 4 files changed, 169 insertions(+), 69 deletions(-)
drivers/net/ethernet/xilinx/Kconfig +1 -0
index 7502214cc7d5..3b940d2d3115 100644
@@ -27,6 +27,7 @@ config XILINX_AXI_EMAC
 	tristate "Xilinx 10/100/1000 AXI Ethernet support"
 	depends on HAS_IOMEM
 	depends on XILINX_DMA
+	select AUXILIARY_BUS
 	select PHYLINK
 	select DIMLIB
 	help
drivers/net/ethernet/xilinx/xilinx_axienet.h +5 -5
index d7215dd92ce9..69665c7f264a 100644
@@ -470,6 +470,7 @@ struct skbuf_dma_descriptor {
 /**
  * struct axienet_common - axienet private common data
  * @pdev: Pointer to common platform device structure
+ * @mac: Pointer to MAC (netdev parent) device structure
  * @axi_clk: AXI4-Lite bus clock
  * @reset_lock: Lock held while resetting the device to prevent register access
  * @mii_bus: Pointer to MII bus structure
@@ -479,11 +480,12 @@ struct skbuf_dma_descriptor {
  */
 struct axienet_common {
 	struct platform_device *pdev;
+	struct auxiliary_device mac;
 
 	struct clk *axi_clk;
 
 	struct mutex reset_lock;
-	struct mii_bus *mii_bus;
+	struct auxiliary_device mii_bus;
 	u8 mii_clk_div;
 
 	void __iomem *regs;
@@ -493,7 +495,7 @@ struct axienet_common {
 /**
  * struct axienet_local - axienet private per device data
  * @ndev:	Pointer for net_device to which it will be attached.
- * @dev:	Pointer to device structure
+ * @dev:	Pointer to parent device structure for DMA access
  * @phylink:	Pointer to phylink instance
  * @phylink_config: phylink configuration settings
  * @pcs_phy:	Reference to PCS/PMA PHY if used
@@ -752,8 +754,6 @@ static inline void axienet_dma_out_addr(struct axienet_local *lp, off_t reg,
 
 #endif /* CONFIG_64BIT */
 
-/* Function prototypes visible in xilinx_axienet_mdio.c for other files */
-int axienet_mdio_setup(struct axienet_common *lp);
-void axienet_mdio_teardown(struct axienet_common *lp);
+extern struct auxiliary_driver xilinx_axienet_mdio;
 
 #endif /* XILINX_AXI_ENET_H */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +136 -32

273 lines not on this page · raw message

drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +27 -32

92 lines not on this page · raw message

Signature · 1 line
2.35.1.1320.gc452695387.dirty
#19 lore raw

Re: [PATCH net-next v4 7/7] net: axienet: Split into MAC and MDIO drivers

Quoted 1 line
Fixes 1a02556086fc ("net: axienet: Properly handle PCS/PMA PHY for 1000BaseX mode")

If this is for net-next, please don't have a Fixes: tag.

drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor { · line 488

Quoted 9 lines

struct axienet_common {

drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -1
 	struct platform_device *pdev;
+	struct auxiliary_device mac;
 
 	struct clk *axi_clk;
 
 	struct mutex reset_lock;
-	struct mii_bus *mii_bus;
+	struct auxiliary_device mii_bus;

Keeping the name mii_bus for something which is not an struct mii_bus is going to cause confusion. Please give it a different name.

This is another patch which needs splitting up.

Andrew

#20 lore raw

Re: [PATCH net-next v4 7/7] net: axienet: Split into MAC and MDIO drivers

Quoted 3 lines · Andrew Lunn
Quoted 1 line
Fixes 1a02556086fc ("net: axienet: Properly handle PCS/PMA PHY for 1000BaseX mode")

If this is for net-next, please don't have a Fixes: tag.

This is a fix. But as explained in the cover letter this is quite an involved fix for an uncommon bug. I can target net if you like.

Quoted 4 lines
Quoted 4 lines

struct axienet_common {

drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
 	struct platform_device *pdev;
+	struct auxiliary_device mac;
Quoted 8 lines

drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor { · line 488

Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -1
 	struct clk *axi_clk;
 
 	struct mutex reset_lock;
-	struct mii_bus *mii_bus;
+	struct auxiliary_device mii_bus;

Keeping the name mii_bus for something which is not an struct mii_bus is going to cause confusion. Please give it a different name.

Like mdio?

Quoted 1 line

This is another patch which needs splitting up.

I don't think it can be split up in any major way. The whole conversion of the MAC/MDIO portions of the driver has to be done at the same time as the parent driver is converted to use them.

--Sean