Skip to contentSkip to conversation

Fix broken link on Xilinx's AXI Ethernet in SGMII mode

PATCH Applied Andy Chiu 4 participants 13 messages Apr 5, 2022 – Apr 6, 2022

Subsystems (5)
lore
Share & tools
lore

Andy Chiu

author
#0 lore raw

v8 cover Fix broken link on Xilinx's AXI Ethernet in SGMII mode

The Ethernet driver use phy-handle to reference the PCS/PMA PHY. This could be a problem if one wants to configure an external PHY via phylink, since it use the same phandle to get the PHY. To fix this, introduce a dedicated pcs-handle to point to the PCS/PMA PHY and deprecate the use of pointing it with phy-handle. A similar use case of pcs-handle can be seen on dpaa2 as well.

--- patch v5 ---
- Re-apply the v4 patch on the net tree.
- Describe the pcs-handle DT binding at ethernet-controller level.
--- patch v6 ---
- Remove "preferrably" to clearify usage of pcs_handle.
--- patch v7 ---
- Rebase the patch on latest net/master
--- patch v8 ---
- Rebase the patch on net-next/master
- Add "reviewed-by" tag in PATCH 3/4: dt-bindings: net: add pcs-handle attribute
- Remove "fix" tag in last commit message since this is not a critical bug and will not be back ported to stable.

Andy Chiu (4):
net: axienet: setup mdio unconditionally
net: axienet: factor out phy_node in struct axienet_local
dt-bindings: net: add pcs-handle attribute
net: axiemac: use a phandle to reference pcs_phy

 .../bindings/net/ethernet-controller.yaml     |  6 ++++
 .../bindings/net/xilinx_axienet.txt           |  8 ++++-
 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  2 --
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 33 ++++++++++---------
 4 files changed, 31 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v8 1/4 net: axienet: setup mdio unconditionally

The call to axienet_mdio_setup should not depend on whether "phy-node" pressents on the DT. Besides, since lp->phy_node is used if PHY is in SGMII or 100Base-X modes, move it into the if statement. And the next patch will remove lp->phy_node from driver's private structure and do an of_node_put on it right away after use since it is not used elsewhere.

---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -7
index c7eb05e4a6bf..78a991bbbcf9 100644
@@ -2064,15 +2064,14 @@ static int axienet_probe(struct platform_device *pdev)
 	if (ret)
 		goto cleanup_clk;
 
-	lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
-	if (lp->phy_node) {
-		ret = axienet_mdio_setup(lp);
-		if (ret)
-			dev_warn(&pdev->dev,
-				 "error registering MDIO bus: %d\n", ret);
-	}
+	ret = axienet_mdio_setup(lp);
+	if (ret)
+		dev_warn(&pdev->dev,
+			 "error registering MDIO bus: %d\n", ret);
+
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
+		lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
 		if (!lp->phy_node) {
 			dev_err(&pdev->dev, "phy-handle required for 1000BaseX/SGMII\n");
 			ret = -EINVAL;
Signature · 1 line
2.34.1
Reviewed-by on v8 1/4
#2 lore raw

Re: [PATCH v8 net-next 1/4] net: axienet: setup mdio unconditionally

Quoted 9 lines · Andy Chiu

The call to axienet_mdio_setup should not depend on whether "phy-node" pressents on the DT. Besides, since lp->phy_node is used if PHY is in SGMII or 100Base-X modes, move it into the if statement. And the next patch will remove lp->phy_node from driver's private structure and do an of_node_put on it right away after use since it is not used elsewhere.

Andrew

Reviewed-by on v8 1/4
#3 lore raw

RE: [PATCH v8 net-next 1/4] net: axienet: setup mdio unconditionally

In reply to Andy Chiu
Quoted 12 lines

-----Original Message-----
From: Andy Chiu <[email protected]>
Sent: Tuesday, April 5, 2022 2:49 PM
To: [email protected]; Michal Simek <[email protected]>; Radhey Shyam Pandey <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andy Chiu <[email protected]>; Greentime Hu <[email protected]>; Robert Hancock <[email protected]>
Subject: [PATCH v8 net-next 1/4] net: axienet: setup mdio unconditionally

Quoted 2 lines

The call to axienet_mdio_setup should not depend on whether "phy-node" pressents on the DT. Besides, since lp->phy_node is used if PHY is in SGMII or

:s/pressents/present

Quoted 7 lines

100Base-X modes, move it into the if statement. And the next patch will remove lp->phy_node from driver's private structure and do an of_node_put on it right away after use since it is not used elsewhere.

Quoted 37 lines
---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -7
index c7eb05e4a6bf..78a991bbbcf9 100644
@@ -2064,15 +2064,14 @@ static int axienet_probe(struct platform_device
 *pdev)
 	if (ret)
 		goto cleanup_clk;
 
-	lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-handle",
 0);
-	if (lp->phy_node) {
-		ret = axienet_mdio_setup(lp);
-		if (ret)
-			dev_warn(&pdev->dev,
-				 "error registering MDIO bus: %d\n", ret);
-	}
+	ret = axienet_mdio_setup(lp);
+	if (ret)
+		dev_warn(&pdev->dev,
+			 "error registering MDIO bus: %d\n", ret);
+
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
+		lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-
 handle", 0);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
 		if (!lp->phy_node) {
 			dev_err(&pdev->dev, "phy-handle required for

1000BaseX/SGMII\n");
ret = -EINVAL;
--
2.34.1

author
#4 lore raw

PATCH v8 2/4 net: axienet: factor out phy_node in struct axienet_local

In reply to Andy Chiu

the struct member phy_node of struct axienet_local is not used by the driver anymore after initialization. It might be a remnent of old code and could be removed.

---
 drivers/net/ethernet/xilinx/xilinx_axienet.h      |  2 --
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 13 +++++--------
 2 files changed, 5 insertions(+), 10 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -2
index 0f9c88dd1a4a..d5c1e5c4a508 100644
@@ -433,8 +433,6 @@ struct axienet_local {
 	struct net_device *ndev;
 	struct device *dev;
 
-	struct device_node *phy_node;
-
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
 
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -8
index 78a991bbbcf9..3daef64a85bd 100644
@@ -2071,17 +2071,19 @@ static int axienet_probe(struct platform_device *pdev)
 
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
-		lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
-		if (!lp->phy_node) {
+		np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+		if (!np) {
 			dev_err(&pdev->dev, "phy-handle required for 1000BaseX/SGMII\n");
 			ret = -EINVAL;
 			goto cleanup_mdio;
 		}
-		lp->pcs_phy = of_mdio_find_device(lp->phy_node);
+		lp->pcs_phy = of_mdio_find_device(np);
 		if (!lp->pcs_phy) {
 			ret = -EPROBE_DEFER;
+			of_node_put(np);
 			goto cleanup_mdio;
 		}
+		of_node_put(np);
 		lp->pcs.ops = &axienet_pcs_ops;
 		lp->pcs.poll = true;
 	}
@@ -2124,8 +2126,6 @@ static int axienet_probe(struct platform_device *pdev)
 		put_device(&lp->pcs_phy->dev);
 	if (lp->mii_bus)
 		axienet_mdio_teardown(lp);
-	of_node_put(lp->phy_node);
-
 cleanup_clk:
 	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	clk_disable_unprepare(lp->axi_clk);
@@ -2154,9 +2154,6 @@ static int axienet_remove(struct platform_device *pdev)
 	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	clk_disable_unprepare(lp->axi_clk);
 
-	of_node_put(lp->phy_node);
-	lp->phy_node = NULL;
-
 	free_netdev(ndev);
 
 	return 0;
Signature · 1 line
2.34.1
Reviewed-by on v8 2/4
#5 lore raw

RE: [PATCH v8 net-next 2/4] net: axienet: factor out phy_node in struct axienet_local

Quoted 13 lines

-----Original Message-----
From: Andy Chiu <[email protected]>
Sent: Tuesday, April 5, 2022 2:49 PM
To: [email protected]; Michal Simek <[email protected]>; Radhey Shyam Pandey <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andy Chiu <[email protected]>; Greentime Hu <[email protected]>; Robert Hancock <[email protected]>
Subject: [PATCH v8 net-next 2/4] net: axienet: factor out phy_node in struct axienet_local

Quoted 7 lines

the struct member phy_node of struct axienet_local is not used by the driver anymore after initialization. It might be a remnent of old code and could be removed.

Quoted 73 lines
---
 drivers/net/ethernet/xilinx/xilinx_axienet.h      |  2 --
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 13 +++++--------
 2 files changed, 5 insertions(+), 10 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -2
index 0f9c88dd1a4a..d5c1e5c4a508 100644
@@ -433,8 +433,6 @@ struct axienet_local {
 	struct net_device *ndev;
 	struct device *dev;
 
-	struct device_node *phy_node;
-
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
 
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -3
index 78a991bbbcf9..3daef64a85bd 100644
@@ -2071,17 +2071,19 @@ static int axienet_probe(struct platform_device
 *pdev)
 
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
-		lp->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-
 handle", 0);
-		if (!lp->phy_node) {
+		np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+		if (!np) {
 			dev_err(&pdev->dev, "phy-handle required for
 1000BaseX/SGMII\n");
 			ret = -EINVAL;
 			goto cleanup_mdio;
 		}
-		lp->pcs_phy = of_mdio_find_device(lp->phy_node);
+		lp->pcs_phy = of_mdio_find_device(np);
 		if (!lp->pcs_phy) {
 			ret = -EPROBE_DEFER;
+			of_node_put(np);
 			goto cleanup_mdio;
 		}
+		of_node_put(np);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -2
 		lp->pcs.ops = &axienet_pcs_ops;
 		lp->pcs.poll = true;
 	}
@@ -2124,8 +2126,6 @@ static int axienet_probe(struct platform_device
 *pdev)
 		put_device(&lp->pcs_phy->dev);
 	if (lp->mii_bus)
 		axienet_mdio_teardown(lp);
-	of_node_put(lp->phy_node);
-
 cleanup_clk:
 	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -3
 	clk_disable_unprepare(lp->axi_clk);
@@ -2154,9 +2154,6 @@ static int axienet_remove(struct platform_device
 *pdev)
 	clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks);
 	clk_disable_unprepare(lp->axi_clk);
 
-	of_node_put(lp->phy_node);
-	lp->phy_node = NULL;
-
 	free_netdev(ndev);
 

return 0;
--
2.34.1

Reviewed-by on v8 2/4
#6 lore raw

Re: [PATCH v8 net-next 2/4] net: axienet: factor out phy_node in struct axienet_local

In reply to Andy Chiu
Quoted 7 lines · Andy Chiu

the struct member phy_node of struct axienet_local is not used by the driver anymore after initialization. It might be a remnent of old code and could be removed.

Andrew

author
#7 lore raw

PATCH v8 3/4 dt-bindings: net: add pcs-handle attribute

In reply to Andy Chiu

Document the new pcs-handle attribute to support connecting to an external PHY. For Xilinx's AXI Ethernet, this is used when the core operates in SGMII or 1000Base-X modes and links through the internal PCS/PMA PHY.

---
 .../devicetree/bindings/net/ethernet-controller.yaml      | 6 ++++++
 Documentation/devicetree/bindings/net/xilinx_axienet.txt  | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/ethernet-controller.yaml +6 -0
index 817794e56227..4f15463611f8 100644
@@ -106,6 +106,12 @@ properties:
   phy-mode:
     $ref: "#/properties/phy-connection-type"
 
+  pcs-handle:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      Specifies a reference to a node representing a PCS PHY device on a MDIO
+      bus to link with an external PHY (phy-handle) if exists.
+
   phy-handle:
     $ref: /schemas/types.yaml#/definitions/phandle
     description:
Documentation/devicetree/bindings/net/xilinx_axienet.txt +7 -1
index b8e4894bc634..1aa4c6006cd0 100644
@@ -26,7 +26,8 @@ Required properties:
 		  specified, the TX/RX DMA interrupts should be on that node
 		  instead, and only the Ethernet core interrupt is optionally
 		  specified here.
-- phy-handle	: Should point to the external phy device.
+- phy-handle	: Should point to the external phy device if exists. Pointing
+		  this to the PCS/PMA PHY is deprecated and should be avoided.
 		  See ethernet.txt file in the same directory.
 - xlnx,rxmem	: Set to allocated memory buffer for Rx/Tx in the hardware
 
@@ -68,6 +69,11 @@ Optional properties:
 		  required through the core's MDIO interface (i.e. always,
 		  unless the PHY is accessed through a different bus).
 
+ - pcs-handle: 	  Phandle to the internal PCS/PMA PHY in SGMII or 1000Base-X
+		  modes, where "pcs-handle" should be used to point
+		  to the PCS/PMA PHY, and "phy-handle" should point to an
+		  external PHY if exists.
+
 Example:
 	axi_ethernet_eth: ethernet@40c00000 {
 		compatible = "xlnx,axi-ethernet-1.00.a";
Signature · 1 line
2.34.1
Reviewed-by on v8 3/4
#8 lore raw

Re: [PATCH v8 net-next 3/4] dt-bindings: net: add pcs-handle attribute

Quoted 8 lines · Andy Chiu

Document the new pcs-handle attribute to support connecting to an external PHY. For Xilinx's AXI Ethernet, this is used when the core operates in SGMII or 1000Base-X modes and links through the internal PCS/PMA PHY.

Andrew

author
#9 lore raw

PATCH v8 4/4 net: axiemac: use a phandle to reference pcs_phy

In reply to Andy Chiu

In some SGMII use cases where both a fixed link external PHY and the internal PCS/PMA PHY need to be configured, we should explicitly use a phandle "pcs-phy" to get the reference to the PCS/PMA PHY. Otherwise, the driver would use "phy-handle" in the DT as the reference to both the external and the internal PCS/PMA PHY.

In other cases where the core is connected to a SFP cage, we could still point phy-handle to the intenal PCS/PMA PHY, and let the driver connect to the SFP module, if exist, via phylink.

---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -2
index 3daef64a85bd..d6fc3f7acdf0 100644
@@ -2071,9 +2071,16 @@ static int axienet_probe(struct platform_device *pdev)
 
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
-		np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+		np = of_parse_phandle(pdev->dev.of_node, "pcs-handle", 0);
 		if (!np) {
-			dev_err(&pdev->dev, "phy-handle required for 1000BaseX/SGMII\n");
+			/* 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);
+		}
+		if (!np) {
+			dev_err(&pdev->dev, "pcs-handle (preferred) or phy-handle required for 1000BaseX/SGMII\n");
 			ret = -EINVAL;
 			goto cleanup_mdio;
 		}
Signature · 1 line
2.34.1
Reviewed-by on v8 4/4
#10 lore raw

Re: [PATCH v8 net-next 4/4] net: axiemac: use a phandle to reference pcs_phy

Quoted 6 lines · Andy Chiu

In some SGMII use cases where both a fixed link external PHY and the internal PCS/PMA PHY need to be configured, we should explicitly use a phandle "pcs-phy" to get the reference to the PCS/PMA PHY. Otherwise, the driver would use "phy-handle" in the DT as the reference to both the external and the internal PCS/PMA PHY.

Quoted 7 lines

In other cases where the core is connected to a SFP cage, we could still point phy-handle to the intenal PCS/PMA PHY, and let the driver connect to the SFP module, if exist, via phylink.

Andrew

Reviewed-by on v8 4/4
#11 lore raw

RE: [PATCH v8 net-next 4/4] net: axiemac: use a phandle to reference pcs_phy

In reply to Andy Chiu
Quoted 13 lines

-----Original Message-----
From: Andy Chiu <[email protected]>
Sent: Tuesday, April 5, 2022 2:49 PM
To: [email protected]; Michal Simek <[email protected]>; Radhey Shyam Pandey <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andy Chiu <[email protected]>; Greentime Hu <[email protected]>; Robert Hancock <[email protected]>
Subject: [PATCH v8 net-next 4/4] net: axiemac: use a phandle to reference pcs_phy

Quoted 8 lines

In some SGMII use cases where both a fixed link external PHY and the internal PCS/PMA PHY need to be configured, we should explicitly use a phandle "pcs- phy" to get the reference to the PCS/PMA PHY. Otherwise, the driver would use "phy-handle" in the DT as the reference to both the external and the internal PCS/PMA PHY.

In other cases where the core is connected to a SFP cage, we could still point phy-handle to the intenal PCS/PMA PHY, and let the driver connect to the SFP

Internal

Quoted 5 lines

module, if exist, via phylink.

Quoted 35 lines
---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -2
index 3daef64a85bd..d6fc3f7acdf0 100644
@@ -2071,9 +2071,16 @@ static int axienet_probe(struct platform_device
 *pdev)
 
 	if (lp->phy_mode == PHY_INTERFACE_MODE_SGMII ||
 	    lp->phy_mode == PHY_INTERFACE_MODE_1000BASEX) {
-		np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+		np = of_parse_phandle(pdev->dev.of_node, "pcs-handle", 0);
 		if (!np) {
-			dev_err(&pdev->dev, "phy-handle required for
 1000BaseX/SGMII\n");
+			/* 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);
+		}
+		if (!np) {
+			dev_err(&pdev->dev, "pcs-handle (preferred) or phy-

handle required

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
+for 1000BaseX/SGMII\n");
 			ret = -EINVAL;
 			goto cleanup_mdio;
 		}
--

2.34.1

#12 lore raw
In reply to Andy Chiu
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Tue, 5 Apr 2022 17:19:25 +0800 you wrote:

The Ethernet driver use phy-handle to reference the PCS/PMA PHY. This could be a problem if one wants to configure an external PHY via phylink, since it use the same phandle to get the PHY. To fix this, introduce a dedicated pcs-handle to point to the PCS/PMA PHY and deprecate the use of pointing it with phy-handle. A similar use case of pcs-handle can be seen on dpaa2 as well.

[...]

Here is the summary with links:
- [v8,net-next,1/4] net: axienet: setup mdio unconditionally

    https://git.kernel.org/netdev/net/c/d1c4f93e3f0a
  - [v8,net-next,2/4] net: axienet: factor out phy_node in struct axienet_local
    https://git.kernel.org/netdev/net/c/ab3a5d4c6081
  - [v8,net-next,3/4] dt-bindings: net: add pcs-handle attribute
    https://git.kernel.org/netdev/net/c/dc48f04fd656
  - [v8,net-next,4/4] net: axiemac: use a phandle to reference pcs_phy
    https://git.kernel.org/netdev/net/c/19c7a43912c6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html