Skip to contentSkip to conversation

net: phy: Add driver for Motorcomm Quad 2.5GbE phy

PATCH Superseded Kyle Switch 4 participants 9 messages Sep 10 – Sep 12

Subsystems (5)

v16 of 29 Superseded Latest is v29 →

lore
Share & tools
lore
#0 lore raw

v16 cover net: phy: Add driver for Motorcomm Quad 2.5GbE phy

Add support for Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver, using the phy_package helpers for the shared top extended register space.

changes in v16:
1. Add DTS documentation.
2. Fix redundant initialization.

changes in v14:
1. Refactor the error return path to preserve and return the initial error, rather than letting later errors mask it.

changes in v13:
1. Fix the lock release issue on the error path to prevent potential deadlock or resource leak.
2. Add a func yt8824_restore_defaults() to restore configuration on the error path, ensuring the hardware/device is left in a known good state upon failure.

changes in v12:
1. Refactor the yt8824_read_status() function to ensure proper state synchronization between hardware registers and the phy_device structure.

changes in v11:
1. Clean build_clang warning.

changes in v10:
1. Within the interface that swaps to the USXGMII reg space,the lock include shared_lock and mdio mutex must remain held throughout the entire operation and should only be released after all steps have completed.
2. Improve the template interface in phy-c45.c
3. Fix the handling of some failure paths.

changes in v9:
1. Add shared_lock mutex prevents UTPs from interfering with each other due to swapping reg space.

change in v8:
1. Clean up format warning.
2. Fix exception handling code logic based on Sashiko/Gemini.
3. Remove interrupt/handle function

changes in v7:
1. Refactor the using of mdio lock
In all cases of swapping to the USXGMII side interface, lock the MDIO bus at the beginning, switch to the UTP address space after the operation is completed, and then release the lock.The purpose of doing this is to ensure that it will not affect other UTPs operating in the UTP address space.
2. Rename YT8824_RSSR_FIBER_SPACE to YT8824_RSSR_USXGMII_SPACE.

changes in v6:
1. Add test mode helper in phy-c45.c
2. Refactor the using of swapping paged for utp and fiber

changes in v5:
1. Fix diffs issue which caused by unexpected whitespace.
2. Fix "exceeding 80 columns" warning.

changes in v4:
1. Remove motorcomm,yt8xxx.yaml, will update in other patch thread
2. Fix locking issue. Since every interface requires switching of space, the bus is already locked during the space switching process in phy_select_page(), other operations within the interface cannot be locked again before unlock in phy_restore_page().
3. Fix warning log identified during the inspection process using checkpatch.pl.
4. Fix the way of using common api in phy_package.c

changes in v3:
1. Using common apis defined in phy_package.c to handle shared top extend register space.
2. Add dts demo in motorcomm,yt8xxx.yaml.
3. Fix unnecessary redundant judgments.
4. Fix BMCR registers operation using magic number.
5. Rename funtion based on its approximate functionality.

changes in v2:
1. Remove duplicate code and replace it with existing api.

Kyle Switch (2):
net: phy: Add driver for Motorcomm Quad 2.5GbE phy
dt-bindings: net: Document Motorcomm YT8824 PHY package

 .../bindings/net/motorcomm,yt8824.yaml        |   63 +
 drivers/net/phy/Kconfig                       |    3 +-
 drivers/net/phy/motorcomm.c                   | 1585 ++++++++++++++++-
 drivers/net/phy/phy-c45.c                     |   55 +
 include/linux/phy.h                           |    1 +
 include/uapi/linux/mdio.h                     |   12 +
 6 files changed, 1716 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH v16 1/2 net: phy: Add driver for Motorcomm Quad 2.5GbE phy

Add support for Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver, using the phy_package helpers for the shared top extended register space.
It also adds a new exported phylib helper, genphy_c45_template_testmode().

---
 drivers/net/phy/Kconfig     |    3 +-
 drivers/net/phy/motorcomm.c | 1585 ++++++++++++++++++++++++++++++++++-
 drivers/net/phy/phy-c45.c   |   55 ++
 include/linux/phy.h         |    1 +
 include/uapi/linux/mdio.h   |   12 +
 5 files changed, 1653 insertions(+), 3 deletions(-)
drivers/net/phy/Kconfig +2 -1
index b4ef927fd4a6..1dd80e06e237 100644
@@ -361,9 +361,10 @@ config MICROSEMI_PHY
 
 config MOTORCOMM_PHY
 	tristate "Motorcomm PHYs"
+	select PHY_PACKAGE
 	help
 	  Enables support for Motorcomm network PHYs.
-	  Currently supports YT85xx Gigabit Ethernet PHYs.
+	  Currently supports YT85xx Gigabit Ethernet PHYs and YT8824 4 * 2.5G PHY.
 
 config NATIONAL_PHY
 	tristate "National Semiconductor PHYs"
drivers/net/phy/motorcomm.c +1583 -2

1,662 lines not on this page · raw message

drivers/net/phy/phy-c45.c +55 -0

61 lines not on this page · raw message

include/linux/phy.h +1 -0
index 3d8afe6b7f1c..fb827cc3c98f 100644
@@ -2357,6 +2357,7 @@ int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed);
 int genphy_c45_pma_resume(struct phy_device *phydev);
 int genphy_c45_pma_suspend(struct phy_device *phydev);
 int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable);
+int genphy_c45_template_testmode(struct phy_device *phydev, int test_mode);
 int genphy_c45_plca_get_cfg(struct phy_device *phydev,
 			    struct phy_plca_cfg *plca_cfg);
 int genphy_c45_plca_set_cfg(struct phy_device *phydev,
include/uapi/linux/mdio.h +12 -0
index 06f4bc3c20c7..8576a48877c6 100644
@@ -63,6 +63,7 @@
 /* Media-dependent registers. */
 #define MDIO_PMA_10GBT_SWAPPOL	130	/* 10GBASE-T pair swap & polarity */
 #define MDIO_PMA_10GBT_TXPWR	131	/* 10GBASE-T TX power control */
+#define MDIO_PMA_10GBT_TESTMODE 132	/* Test mode control */
 #define MDIO_PMA_10GBT_SNR	133	/* 10GBASE-T SNR margin, lane A.
 					 * Lanes B-D are numbered 134-136. */
 #define MDIO_PMA_10GBR_FSRT_CSR	147	/* 10GBASE-R fast retrain status and control */
@@ -320,6 +321,17 @@
 /* PMA 10GBASE-R Fast Retrain status and control register. */
 #define MDIO_PMA_10GBR_FSRT_ENABLE	0x0001	/* Fast retrain enable */
 
+/* PMA 10GBASE-T Template Test Mode Register*/
+#define MDIO_PMA_10GBT_TESTMODE_MASK 0xE000	/* Template test mode */
+#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0000	/* Template Normal */
+#define MDIO_PMA_10GBT_TESTMODE_1 0x2000 /* Template TestMode1 */
+#define MDIO_PMA_10GBT_TESTMODE_2 0x4000 /* Template TestMode2 */
+#define MDIO_PMA_10GBT_TESTMODE_3 0x6000 /* Template TestMode3 */
+#define MDIO_PMA_10GBT_TESTMODE_4 0x8000 /* Template TestMode4 */
+#define MDIO_PMA_10GBT_TESTMODE_5 0xa000 /* Template TestMode5 */
+#define MDIO_PMA_10GBT_TESTMODE_6 0xc000 /* Template TestMode6 */
+#define MDIO_PMA_10GBT_TESTMODE_7 0xe000 /* Template TestMode7 */
+
 /* PCS 10GBASE-R/-T status register 1. */
 #define MDIO_PCS_10GBRT_STAT1_BLKLK	0x0001	/* Block lock attained */
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH v16 2/2 dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Kyle Switch

Document Motorcomm YT8824 PHY package.

Motorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.

Document the required property to make the PHY package correctly configure and work.

---
 .../bindings/net/motorcomm,yt8824.yaml        | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +63 -0
new file mode 100644
index 000000000000..9907a4a7e63e
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/motorcomm,yt8824.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MotorComm YT8824 Ethernet PHY
+
+maintainers:
+  - Kyle Switch <[email protected]>
+
+description: |
+  Motorcomm YT8824 Ethernet PHY is a PHY package of 4 PHYs.
+
+$ref: ethernet-phy-package.yaml#
+
+properties:
+  compatible:
+    enum:
+      - ethernet-phy-id4f51.e8b8
+
+  motorcomm,interface-mode:
+    description: |
+      PHY package interface mode.
+    $ref: /schemas/types.yaml#/definitions/string
+    enum:
+      - internal
+      - usxgmii
+    default: internal
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-phy-package@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "ethernet-phy-id4f51.e8b8";
+            reg = <9>;
+
+            motorcomm,interface-mode = "usxgmii";
+
+            ethernet-phy@4 {
+                reg = <4>;
+            };
+
+            ethernet-phy@5 {
+                reg = <5>;
+            };
+
+            ethernet-phy@6 {
+                reg = <6>;
+            };
+
+            ethernet-phy@7 {
+                reg = <7>;
+            };
+        };
+    };
Signature · 1 line
2.25.1
#2 lore raw
In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing `return 0;` on success path causes unintended execution of error cleanup code. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing return 0; on success path causes unintended execution of error cleanup code. --

commit 9c78ead4e6ec97a6c3f67882266f516e5930cc7c
Author: Kyle Switch <[email protected]>

net: phy: Add driver for Motorcomm Quad 2.5GbE phy

This commit adds support for the Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver. It implements the phy_package helpers to handle the shared top extended register space and introduces a new exported phylib helper, genphy_c45_template_testmode.

Quoted 4 lines
drivers/net/phy/motorcomm.c +0 -0
index c5a2cda8d31bd..d535fd384e7bb 100644

[ ... ]

Quoted 2 lines
drivers/net/phy/motorcomm.c +2 -0
+static int yt8824_internal_config_init_paged(struct phy_device *phydev)
+{

[ ... ]

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+	ret = genphy_c45_template_testmode
+		(phydev, YT8824_UTP_TEMPLATE_TEST_MODE1);
+	if (ret)
+		goto err_restore_normal;
+	/* reset */
+	ret = phy_modify(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE,
+			 BMCR_RESET | BMCR_ANENABLE);
+	if (ret < 0)
+		goto err_restore_normal;
+	ret = phy_read_poll_timeout(phydev, MII_BMCR, val,

drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 1724

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+				    !(val & BMCR_RESET),
+				    50000, 600000, true);
+	if (ret < 0)
+		goto err_restore_normal;
+
+	ret = genphy_c45_template_testmode
+		(phydev, YT8824_UTP_TEMPLATE_TEST_NORMAL);
+	if (ret < 0)
+		goto err_restore_normal;
+

[Severity: Medium]
Does this code accidentally fall through into the error cleanup path?

In yt8824_internal_config_init_paged(), the success path executes genphy_c45_template_testmode() but misses a return statement before the err_restore label. As a result, it unconditionally falls through to:

err_restore:

	r = phy_modify(phydev, MII_BMCR, BMCR_PDOWN, 0);

This will inadvertently clear the BMCR_PDOWN bit at the end of the initialization function instead of keeping it in the expected power-down state until it is explicitly resumed. Sister functions like yt8824_extern_config_utp_init_paged() appear to handle this correctly by including a return 0; statement here.

Quoted 16 lines
drivers/net/phy/motorcomm.c +16 -0
+err_restore:
+	r = phy_modify(phydev, MII_BMCR, BMCR_PDOWN, 0);
+	if (ret >= 0 && r < 0)
+		ret = r;
+	return ret;
+
+err_restore_normal:
+	r = genphy_c45_template_testmode(phydev,
+					 YT8824_UTP_TEMPLATE_TEST_NORMAL);
+	if (ret >= 0 && r < 0)
+		ret = r;
+	r = phy_modify(phydev, MII_BMCR, BMCR_PDOWN, 0);
+	if (ret >= 0 && r < 0)
+		ret = r;
+	return ret;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH v16 2/2] dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Misuse of a standard hardware PHY ID string as the compatible string for an Ethernet PHY package…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Misuse of a standard hardware PHY ID string as the compatible string for an Ethernet PHY package container node.
- [Low] Mismatch between the node name unit-address and its 'reg' property in the example.
- [Low] The YAML binding completely omits the 'required' block, failing to enforce mandatory properties. --

commit 086492b3eff200332b4ab4eddc5f5f7362981d4f
Author: Kyle Switch <[email protected]>

dt-bindings: net: Document Motorcomm YT8824 PHY package

Motorcomm YT8824 Ethernet PHY is a PHY package of 4 PHY-s. This commit documents the required property to make the PHY package correctly configure and work.

Quoted 5 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +0 -0
new file mode 100644
index 0000000000000..9907a4a7e63e8

[ ... ]

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 20

Quoted 4 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +4 -0
+properties:
+  compatible:
+    enum:
+      - ethernet-phy-id4f51.e8b8

[Severity: Medium]
Does this misuse a standard hardware PHY ID string as the compatible string for an Ethernet PHY package container node?

dt-schema selects bindings based on the compatible property. Because ethernet-phy-id4f51.e8b8 is an ID format strictly reserved for individual hardware PHY child nodes (as defined by the pattern in ethernet-phy.yaml), using it for the parent package container causes dt-schema to incorrectly apply this package schema to individual child PHY nodes when running make dt_binding_check on device trees containing these PHYs.

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 32

Quoted 12 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +12 -0
+
+  motorcomm,interface-mode:
+    description: |
+      PHY package interface mode.
+    $ref: /schemas/types.yaml#/definitions/string
+    enum:
+      - internal
+      - usxgmii
+    default: internal
+
+unevaluatedProperties: false
+

[Severity: Low]
Does this YAML binding completely omit the required block, failing to enforce mandatory properties?

Standard Device Tree schema design mandates that mandatory properties, specifically compatible, be explicitly listed in a required block. Without it, the schema validation will not enforce the presence of the compatible property on matching nodes, leading to incomplete validation.

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 43

Quoted 11 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +11 -0
+examples:
+  - |
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-phy-package@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "ethernet-phy-id4f51.e8b8";
+            reg = <9>;

[Severity: Low]
Is there a mismatch between the node name unit-address and its reg property in this example?

The example block defines the node as ethernet-phy-package@0 but specifies reg = <9>. The Device Tree specification requires that the unit address in the node name (the part after @) must exactly match the first address specified in the reg property. This will cause a unit_address_vs_reg or simple_bus_reg warning during compilation and validation.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH v16 2/2] dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Kyle Switch
Quoted 3 lines · Kyle Switch

Document Motorcomm YT8824 PHY package.

Motorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.

One sentence is enough. "Document foo bar, a baz bam something".

Quoted 3 lines

Document the required property to make the PHY package correctly configure and work.

This is redundant sentence.

Quoted 4 lines
---
 .../bindings/net/motorcomm,yt8824.yaml        | 63 +++++++++++++++++++

Please organize the patch documenting the compatible (DT bindings)
before the patch using that compatible.
See also: https://elixir.bootlin.com/linux/v6.14-rc6/source/Documentation/devicetree/bindings/submitting-patches.rst#L46

Quoted 11 lines
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +2 -0
new file mode 100644
index 000000000000..9907a4a7e63e
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 12

Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10 -0
+---
+$id: http://devicetree.org/schemas/net/motorcomm,yt8824.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MotorComm YT8824 Ethernet PHY
+
+maintainers:
+  - Kyle Switch <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 22

Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10 -0
+  Motorcomm YT8824 Ethernet PHY is a PHY package of 4 PHYs.
+
+$ref: ethernet-phy-package.yaml#
+
+properties:
+  compatible:
+    enum:
+      - ethernet-phy-id4f51.e8b8
+
+  motorcomm,interface-mode:

Aren't you duplicating protocol-names from
/schemas/phy/phy-common-props.yaml?

Best regards,
Krzysztof

maintainer
#7 lore raw

Re: [PATCH v16 2/2] dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Kyle Switch

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 29

Quoted 8 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +8 -0
+  motorcomm,interface-mode:
+    description: |
+      PHY package interface mode.
+    $ref: /schemas/types.yaml#/definitions/string
+    enum:
+      - internal
+      - usxgmii
+    default: internal

You are not the first vendor to use usxgmii, a vendor property is not required.. e.g. fsl-ls1028a-qds-13bb.dtso.

Andrew

#8 lore raw

Re: [PATCH v16 2/2] dt-bindings: net: Document Motorcomm YT8824 PHY package

Quoted 10 lines · Andrew Lunn

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 29

Quoted 8 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +8 -0
+  motorcomm,interface-mode:
+    description: |
+      PHY package interface mode.
+    $ref: /schemas/types.yaml#/definitions/string
+    enum:
+      - internal
+      - usxgmii
+    default: internal

You are not the first vendor to use usxgmii, a vendor property is not required.. e.g. fsl-ls1028a-qds-13bb.dtso.

Ans: will be fixed done in next patch.

Quoted 1 line

Andrew

#6 lore raw

Re: [PATCH v16 2/2] dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Krzysztof Kozlowski
Quoted 5 lines · Krzysztof Kozlowski
Quoted 3 lines · Kyle Switch

Document Motorcomm YT8824 PHY package.

Motorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.

One sentence is enough. "Document foo bar, a baz bam something".

Ans: will be removed in next patch version.

Quoted 3 lines
Quoted 2 lines

Document the required property to make the PHY package correctly configure and work.

This is redundant sentence.

Ans: will be removed in next patch version.

Quoted 7 lines
Quoted 3 lines
---
  .../bindings/net/motorcomm,yt8824.yaml        | 63 +++++++++++++++++++

Please organize the patch documenting the compatible (DT bindings)
before the patch using that compatible.
See also: https://elixir.bootlin.com/linux/v6.14-rc6/source/Documentation/devicetree/bindings/submitting-patches.rst#L46

Ans: okay, the next patch version will swap the order of the two patches.

Quoted 15 lines
Quoted 15 lines
  1 file changed, 63 insertions(+)

create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +6 -0
new file mode 100644
index 000000000000..9907a4a7e63e
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/motorcomm,yt8824.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
Quoted 8 lines

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 12

Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +6 -0
+title: MotorComm YT8824 Ethernet PHY
+
+maintainers:
+  - Kyle Switch <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

Ans: will be removed in next patch version.

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +4 -0
+  Motorcomm YT8824 Ethernet PHY is a PHY package of 4 PHYs.
+
+$ref: ethernet-phy-package.yaml#
+
Quoted 9 lines

Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 22

Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +6 -0
+properties:
+  compatible:
+    enum:
+      - ethernet-phy-id4f51.e8b8
+
+  motorcomm,interface-mode:

Aren't you duplicating protocol-names from
/schemas/phy/phy-common-props.yaml?

Ans: will be fixed done in next patch version.

Quoted 2 lines

Best regards,
Krzysztof