Skip to contentSkip to conversation

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

PATCH Superseded Kyle Switch 5 participants 12 messages Sep 30 – Oct 14

Subsystems (5)

v23 of 29 Superseded Latest is v29 →

lore
Share & tools
lore
#0 lore raw

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

This patchset mainly implements the phy8824 driver. The phy8824 is an Ethernet PHY that provides one 10G SerDes output to four 2.5G ports. The driver mainly covers two application scenarios:
1. external PHY8824
2. PHY8824 embedded in a switch.
The patchset mainly consists of three parts:
1. the DTS for the phy8824
2. a generic template testmode configuration api.
3. the phy8824 functional functions.

changes in v23:
1) Remove meaningless comments in driver.
2) Using #define to replace magic numbers during PHY8824 init.

changes in v22:
1) Using motorcomm,package-mode to replace phy-mode in DTS.
2) The corresponding parsing has also been updated, using "motorcomm,package-mode".

changes in v21:
patch 1: 1) Add maintainer for motorcomm,yt8824.yaml.
2) Using 10g-qxgmii instead of usxgmii.
patch 3: 1) Change the usxgmii space to serdes space.
2) Add lock operation during phy-package init in probe()
3) Add check for whether auto-negotiation is enabled when updating the link status in read_status().

changes in v20:
patch 1: Add phy-mode description in properties in motorcomm,yt8824.yaml

changes in v19:
patch 2: Replace the int type with the u16 type for test_mode. patch 3: 1) Merge yt8824_utp_normal_test_mode_paged() and

         yt8824_utp_invalid_test_mode_paged() into 
         yt8824_utp_set_template_test_mode().

2) Add a fatal error return when phy-mode is missing in the DTS.

changes in v18:
1. Split the template_testmode() into a small patch and optimize the implementation.
2. Optimize the definition and initialization of interface_mode by adopting the existing approach.

changes in v17:
patch 1: Remove redundant description.
Use phy-mode instead of motorcomm,interface to describe the interface.
Add the required checks.
patch 2: Use phy-mode to get interface mode.
Need return after init configuration is done to avoid falling into the error path.

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 function based on its approximate functionality.

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

Kyle Switch (3):
dt-bindings: net: Document Motorcomm YT8824 PHY package
net: phy: Add support for Template Control register for PMA
net: phy: Add driver for Motorcomm Quad 2.5GbE phy

 .../bindings/net/motorcomm,yt8824.yaml        |   78 +
 MAINTAINERS                                   |    2 +
 drivers/net/phy/Kconfig                       |    3 +-
 drivers/net/phy/motorcomm.c                   | 1887 ++++++++++++++++-
 drivers/net/phy/phy-c45.c                     |   23 +
 include/linux/phy.h                           |    1 +
 include/uapi/linux/mdio.h                     |   12 +
 7 files changed, 2003 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH v23 1/3 dt-bindings: net: Document Motorcomm YT8824 PHY package

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

---
 .../bindings/net/motorcomm,yt8824.yaml        | 78 +++++++++++++++++++
 MAINTAINERS                                   |  2 +
 2 files changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +78 -0
new file mode 100644
index 000000000000..4c67f8afcf27
@@ -0,0 +1,78 @@
+# 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:
+      - motorcomm,yt8824-package
+
+  motorcomm,package-mode:
+    description: |
+      PHY package can be configured in 2 modes:
+      - internal: YT8824 is embedded in the switch, using
+        an internal interface to the MAC.
+      - 10g-qxgmii: YT8824 is a standalone external PHY,
+        connected via 10G QXGMII.
+    $ref: /schemas/types.yaml#/definitions/string
+    enum: [ internal, 10g-qxgmii ]
+
+  reg:
+    description:
+      The absolute MDIO address of the YT8824 shared top extend
+      register block.
+      For internal mode, this is fixed at 9;
+      For external mode, it is the base MDIO address of the four
+      member PHYs plus 4, where base is typically 0x0.
+      Note that this is NOT the reg of the first member PHY.
+
+required:
+  - compatible
+  - motorcomm,package-mode
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-phy-package@9 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "motorcomm,yt8824-package";
+            reg = <9>;
+
+            motorcomm,package-mode = "internal";
+
+            ethernet-phy@4 {
+                reg = <4>;
+            };
+
+            ethernet-phy@5 {
+                reg = <5>;
+            };
+
+            ethernet-phy@6 {
+                reg = <6>;
+            };
+
+            ethernet-phy@7 {
+                reg = <7>;
+            };
+        };
+    };
MAINTAINERS +2 -0
index 51873349ba91..a322b49fcfc6 100644
@@ -18413,8 +18413,10 @@ F:	drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
 
 MOTORCOMM PHY DRIVER
 M:	Frank <[email protected]>
+M:	Kyle Switch <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
 F:	Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml
 F:	drivers/net/phy/motorcomm.c
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH v23 2/3 net: phy: Add support for Template Control register for PMA

In reply to Kyle Switch

Add support for the 10GBASE-T PMA Template Test Mode register field, which allows selecting one of eight test modes (Normal and TestMode1..TestMode7) used for PHY validation.

---
 drivers/net/phy/phy-c45.c | 23 +++++++++++++++++++++++
 include/linux/phy.h       |  1 +
 include/uapi/linux/mdio.h | 12 ++++++++++++
 3 files changed, 36 insertions(+)
drivers/net/phy/phy-c45.c +23 -0
index 870920311f9a..c5f5753f7194 100644
@@ -1408,6 +1408,29 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable)
 }
 EXPORT_SYMBOL_GPL(genphy_c45_fast_retrain);
 
+/**
+ * genphy_c45_template_testmode - configure template testmode registers
+ * @phydev: target phy_device struct
+ * @test_mode: testmode includes Normal to Test mode 7
+ *
+ * Description: Set template testmode include Normal to Test mode 7
+ *
+ * Return: 0 on success, or a negative error code on failure (e.g. register
+ * read/write error).
+ */
+int genphy_c45_template_testmode(struct phy_device *phydev, u16 test_mode)
+{
+	u16 ctrl;
+
+	if (test_mode > MDIO_PMA_10GBT_TESTMODE_7)
+		return -EOPNOTSUPP;
+
+	ctrl = FIELD_PREP(MDIO_PMA_10GBT_TESTMODE_MASK, test_mode);
+	return phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TESTMODE,
+			      MDIO_PMA_10GBT_TESTMODE_MASK, ctrl);
+}
+EXPORT_SYMBOL_GPL(genphy_c45_template_testmode);
+
 /**
  * genphy_c45_plca_get_cfg - get PLCA configuration from standard registers
  * @phydev: target phy_device struct
include/linux/phy.h +1 -0
index 7c5098a0dd6c..b9dee2655e6b 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, u16 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..353ca13c64fc 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 GENMASK(15, 13) /* Template test mode */
+#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0 /* Template Normal */
+#define MDIO_PMA_10GBT_TESTMODE_1 0x1 /* Template TestMode1 */
+#define MDIO_PMA_10GBT_TESTMODE_2 0x2 /* Template TestMode2 */
+#define MDIO_PMA_10GBT_TESTMODE_3 0x3 /* Template TestMode3 */
+#define MDIO_PMA_10GBT_TESTMODE_4 0x4 /* Template TestMode4 */
+#define MDIO_PMA_10GBT_TESTMODE_5 0x5 /* Template TestMode5 */
+#define MDIO_PMA_10GBT_TESTMODE_6 0x6 /* Template TestMode6 */
+#define MDIO_PMA_10GBT_TESTMODE_7 0x7 /* 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
#6 lore raw

PATCH v23 3/3 net: phy: Add driver for Motorcomm Quad 2.5GbE phy

In reply to Kyle Switch

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.

---
 drivers/net/phy/Kconfig     |    3 +-
 drivers/net/phy/motorcomm.c | 1887 ++++++++++++++++++++++++++++++++++-
 2 files changed, 1887 insertions(+), 3 deletions(-)
drivers/net/phy/Kconfig +2 -1
index d3835597e379..996d75afed44 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 +1885 -2

1,964 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#7 lore raw

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

Quoted 4 lines · On Thu, 1 Oct 2026 03:45:13 +0800 Kyle Switch wrote:
drivers/net/phy/motorcomm.c +4 -0
+	/* 100M template amplitude */
+	ctrl = FIELD_PREP(YT8824_DAC_IMID_CH3_ORG, 0x45);
+	ctrl |= FIELD_PREP(YT8824_DAC_IMID_CH2_ORG, 0x45);
+	mask = YT8824_DAC_IMID_CH3_ORG | YT8824_DAC_IMID_CH3_ORG;

cocci says:

drivers/net/phy/motorcomm.c:1372:8-31: duplicated argument to & or |

Please also wait for the AI review to be published before reposting.

Signature · 1 line
pw-bot: cr
#8 lore raw
In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net: phy: motorcomm: missing phy_package_init_once in yt8824_config_init disrupts active ports…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: phy: motorcomm: missing phy_package_init_once in yt8824_config_init disrupts active ports
- [High] net: phy: motorcomm: missing U0 un-reset write leaves U0 TX channels permanently disabled
- [Medium] net: phy: motorcomm: incorrect mask in yt8824_config_utp_init_paged causes CH2 register corruption --

commit 198ccc56ee2557369512bc1763b9592679651225
Author: Kyle Switch <[email protected]>

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

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

Quoted 4 lines
drivers/net/phy/motorcomm.c +0 -0
index 90a4f86f2758b..dfa0612d713cb 100644

[ ... ]

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

[ ... ]

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

Quoted 4 lines
drivers/net/phy/motorcomm.c +4 -0
+	/* 100M template amplitude */
+	ctrl = FIELD_PREP(YT8824_DAC_IMID_CH3_ORG, 0x45);
+	ctrl |= FIELD_PREP(YT8824_DAC_IMID_CH2_ORG, 0x45);
+	mask = YT8824_DAC_IMID_CH3_ORG | YT8824_DAC_IMID_CH3_ORG;

[Severity: Medium]
Should this mask clear YT8824_DAC_IMID_CH2_ORG instead of duplicating YT8824_DAC_IMID_CH3_ORG? The CH2 bits don't seem to be cleared before being modified, which might lead to incorrect transmission amplitude on CH2.

Quoted 5 lines
drivers/net/phy/motorcomm.c +5 -0
+	ret = ytphy_modify_ext_with_lock(phydev,
+					 YT8824_DAC_IMID_CH2_CH3_CFG_ORG_REG,
+					 mask, ctrl);
+	if (ret < 0)
+		goto err_restore;

[ ... ]

Quoted 5 lines
drivers/net/phy/motorcomm.c +5 -0
+	ctrl = FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH0, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH1, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH2, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH3, 1);
+	mask = YT8824_U0_CSR_RESETB_TX_CH0 | YT8824_U0_CSR_RESETB_TX_CH1 |

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

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+	       YT8824_U0_CSR_RESETB_TX_CH2 | YT8824_U0_CSR_RESETB_TX_CH3;
+
+	ctrl = FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH0, 1);
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH1, 1);
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH2, 1);
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH3, 1);
+	mask = YT8824_U1_CSR_RESETB_TX_CH0 | YT8824_U1_CSR_RESETB_TX_CH1 |
+	       YT8824_U1_CSR_RESETB_TX_CH2 | YT8824_U1_CSR_RESETB_TX_CH3;
+	ret = ytphy_modify_ext_with_lock(phydev, YT8824_U1_CRS_RESET_REG,
+					 mask, ctrl);

[Severity: High]
Is the ytphy_modify_ext_with_lock() call for YT8824_U0_CRS_RESET_REG missing here? Since ctrl and mask for U0 are immediately overwritten by U1's values before a write occurs, the un-reset sequence is completely skipped for U0. This appears to leave half of the quad PHY's transmit channels permanently disabled.

Quoted 2 lines
drivers/net/phy/motorcomm.c +2 -0
+	if (ret < 0)
+		goto err_restore;

[ ... ]

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

Quoted 12 lines
drivers/net/phy/motorcomm.c +12 -0
+static int yt8824_config_init(struct phy_device *phydev)
+{
+	struct yt8824_shared_priv *priv = phy_package_get_priv(phydev);
+	int ret;
+
+	mutex_lock(&priv->shared_lock);
+	if (priv->package_mode == PHY_INTERFACE_MODE_INTERNAL) {
+		ret = yt8824_config_utp_init_paged(phydev);
+		if (ret < 0)
+			goto err;
+	} else {
+		ret = yt8824_extern_config_sds_init_paged(phydev);

[Severity: High]
Does this initialization need to be guarded by phy_package_init_once()?

The Linux PHY library calls config_init individually for each PHY port on the device when it is brought up. Unconditionally executing the shared SERDES initialization for every port could overwrite shared configurations and assert global hardware resets on other active ports within the same PHY package.

Quoted 8 lines
drivers/net/phy/motorcomm.c +8 -0
+		if (ret < 0)
+			goto err;
+		ret = yt8824_config_utp_init_paged(phydev);
+		if (ret < 0)
+			goto err;
+	}
+	mutex_unlock(&priv->shared_lock);
+	ret = yt8824_soft_reset(phydev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#4 lore raw

Re: [PATCH net-next v23 2/3] net: phy: Add support for Template Control register for PMA

In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] mdio: uapi: unshifted test mode constants and GENMASK break userspace - [Low] phy…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] mdio: uapi: unshifted test mode constants and GENMASK break userspace
- [Low] phy: genphy_c45_template_testmode returns -EOPNOTSUPP instead of -EINVAL
- [Low] phy: vendor-specific 'Template' terminology pollutes generic API
--

commit 60718c14fbea745ac1034f4e3a4c75164fce8bb3
Author: Kyle Switch <[email protected]>

net: phy: Add support for Template Control register for PMA

Add support for the 10GBASE-T PMA Template Test Mode register field, which allows selecting one of eight test modes (Normal and TestMode1..TestMode7) used for PHY validation.

Quoted 4 lines
drivers/net/phy/phy-c45.c +0 -0
index 870920311f9a0..c5f5753f7194b 100644

[ ... ]

Quoted 5 lines
drivers/net/phy/phy-c45.c +1 -0
@@ -1408,6 +1408,29 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable)
 }
 EXPORT_SYMBOL_GPL(genphy_c45_fast_retrain);
 
+/**

drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1421

Quoted 10 lines
drivers/net/phy/phy-c45.c +10 -0
+ * genphy_c45_template_testmode - configure template testmode registers
+ * @phydev: target phy_device struct
+ * @test_mode: testmode includes Normal to Test mode 7
+ *
+ * Description: Set template testmode include Normal to Test mode 7
+ *
+ * Return: 0 on success, or a negative error code on failure (e.g. register
+ * read/write error).
+ */
+int genphy_c45_template_testmode(struct phy_device *phydev, u16 test_mode)

[Severity: Low]
Is it appropriate to use the vendor-specific term Template in the generic PHY API?

This terminology doesn't appear to exist in the IEEE 802.3 specification for the 10GBASE-T test mode register (1.132, Clause 45.2.1.75). Using it here and in the UAPI header may mislead developers using the generic PHY headers.

drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1426

Quoted 5 lines
drivers/net/phy/phy-c45.c +5 -0
+{
+	u16 ctrl;
+
+	if (test_mode > MDIO_PMA_10GBT_TESTMODE_7)
+		return -EOPNOTSUPP;

[Severity: Low]
Should this bounds check return -EINVAL instead of -EOPNOTSUPP?

Returning -EOPNOTSUPP implies the hardware doesn't support the test mode feature at all, while the actual problem here is that the provided argument is invalid.

Quoted 6 lines
drivers/net/phy/phy-c45.c +6 -0
+
+	ctrl = FIELD_PREP(MDIO_PMA_10GBT_TESTMODE_MASK, test_mode);
+	return phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TESTMODE,
+			      MDIO_PMA_10GBT_TESTMODE_MASK, ctrl);
+}
+EXPORT_SYMBOL_GPL(genphy_c45_template_testmode);

[ ... ]

Quoted 4 lines
include/uapi/linux/mdio.h +0 -0
index 06f4bc3c20c71..353ca13c64fca 100644

[ ... ]

include/uapi/linux/mdio.h line 327

Quoted 8 lines
include/uapi/linux/mdio.h +4 -0
@@ -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 GENMASK(15, 13) /* Template test mode */
+#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0 /* Template Normal */
+#define MDIO_PMA_10GBT_TESTMODE_1 0x1 /* Template TestMode1 */

[Severity: Medium]
Will this break compilation for userspace applications since GENMASK is a kernel-internal macro?

Also, the constants are exported as unshifted values (e.g., 0x1) without a corresponding shift macro. Since userspace applications don't have access to FIELD_PREP(), applications attempting to use these constants directly will erroneously set bit 0 instead of bit 13, leading to silent hardware misconfiguration.

Quoted 7 lines
include/uapi/linux/mdio.h +7 -0
+#define MDIO_PMA_10GBT_TESTMODE_2 0x2 /* Template TestMode2 */
+#define MDIO_PMA_10GBT_TESTMODE_3 0x3 /* Template TestMode3 */
+#define MDIO_PMA_10GBT_TESTMODE_4 0x4 /* Template TestMode4 */
+#define MDIO_PMA_10GBT_TESTMODE_5 0x5 /* Template TestMode5 */
+#define MDIO_PMA_10GBT_TESTMODE_6 0x6 /* Template TestMode6 */
+#define MDIO_PMA_10GBT_TESTMODE_7 0x7 /* Template TestMode7 */
+
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#2 lore raw

Re: [PATCH net-next v23 1/3] dt-bindings: net: Document Motorcomm YT8824 PHY package

In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In motorcomm,yt8824.yaml, the rules for the package reg exist only as prose, and the schema does not enforce them.

--

dt-bindings: net: Document Motorcomm YT8824 PHY package

This commit adds a new DT binding schema for the Motorcomm YT8824 quad PHY package. The schema is based on ethernet-phy-package.yaml, and a vendor property, motorcomm,package-mode, selects internal or 10g-qxgmii mode. The commit also adds the new file and a co-maintainer to the MOTORCOMM PHY DRIVER entry in MAINTAINERS.

Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +0 -0
new file mode 100644
index 0000000000000..4c67f8afcf27a
@@ -0,0 +1,78 @@

[ ... ]

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

Quoted 8 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +8 -0
+  reg:
+    description:
+      The absolute MDIO address of the YT8824 shared top extend
+      register block.
+      For internal mode, this is fixed at 9;
+      For external mode, it is the base MDIO address of the four
+      member PHYs plus 4, where base is typically 0x0.
+      Note that this is NOT the reg of the first member PHY.

[Severity: Low]
The rules for reg are only in the description text. No allOf/if-then block ties reg to motorcomm,package-mode, so this node would pass dt_binding_check:

    motorcomm,package-mode = "internal";
    reg = <4>;

That passes even though the description says reg is fixed at 9 in internal mode. Could an if/then be added that requires reg to be 9 when motorcomm,package-mode is "internal"?

The value matters at runtime, because of_phy_package_join() uses the package reg as base_addr:

drivers/net/phy/phy_package.c:of_phy_package_join() {
    ...
	if (of_property_read_u32(package_node, "reg", &base_addr)) {
		ret = -EINVAL;
		goto exit;
	}

	ret = phy_package_join(phydev, base_addr, priv_size);
    ...
}

The driver added later in the series ("net: phy: Add driver for Motorcomm Quad 2.5GbE phy") has ytphy_read_top_ext() and ytphy_write_top_ext(). Both access the shared top block through __phy_package_read() and __phy_package_write() with offset 0, so they go to exactly that address.

The inherited ethernet-phy-package.yaml describes reg as "Commonly the ID of the first PHY in the PHY package". That is the value this binding says not to use.

If a board DT sets reg to the first member PHY's address, would the top-block page select and data writes end up in that member PHY's register space?

The two modes also seem to use different address layouts. In the internal-mode example below, the member PHYs are at 4-7 and the top block is at 9. That is base plus 5, with 8 unused. External mode is described as base plus 4.

Is that difference real in the hardware? If so, could the description say so explicitly?

[ ... ]

Quoted 11 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +11 -0
+        ethernet-phy-package@9 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "motorcomm,yt8824-package";
+            reg = <9>;
+
+            motorcomm,package-mode = "internal";
+
+            ethernet-phy@4 {
+                reg = <4>;
+            };

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930194513.663575-1-kyle.switch%40motor-comm.com
#5 lore raw

Re: [PATCH net-next v23 2/3] net: phy: Add support for Template Control register for PMA

In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch adds MDIO_PMA_10GBT_TESTMODE_MASK to the exported uAPI header include/uapi/linux/mdio.h as GENMASK(15, 13).
- [Low] phy: genphy_c45_template_testmode returns -EOPNOTSUPP instead of -EINVAL
- [Low] phy: vendor-specific 'Template' terminology pollutes generic API

--

net: phy: Add support for Template Control register for PMA

This commit adds the genphy_c45_template_testmode() helper. The helper writes the 10GBASE-T PMA test mode field in register 132. The commit also adds the register and field definitions to the uapi mdio.h header.

Quoted 4 lines
include/uapi/linux/mdio.h +0 -0
index 06f4bc3c20c71..353ca13c64fca 100644

[ ... ]

include/uapi/linux/mdio.h line 325

Quoted 6 lines
include/uapi/linux/mdio.h +2 -0
@@ -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 GENMASK(15, 13) /* Template test mode */

[Severity: Low]
Will this build in userspace? include/uapi/linux/mdio.h is an exported header, and GENMASK() isn't defined for userspace.

The uapi header only includes these:

include/uapi/linux/mdio.h:

    #include <linux/types.h>
    #include <linux/mii.h>

Neither of them, nor anything they pull in (ethtool.h, const.h, if_ether.h, ...), defines GENMASK(). The uapi <linux/bits.h> only provides __GENMASK(), __GENMASK_ULL() and __GENMASK_U128().

In the kernel this only works because the internal wrapper includes bitfield.h right after the uapi header:

include/linux/mdio.h:

    #include <uapi/linux/mdio.h>
    #include <linux/bitfield.h>

So a userspace program that includes <linux/mdio.h> and uses MDIO_PMA_10GBT_TESTMODE_MASK would fail to compile with an undefined GENMASK.

This file already has the same problem in MDIO_AN_C73_0_S_MASK, MDIO_AN_C73_0_E_MASK and MDIO_AN_C73_1_T_MASK. This patch adds one more exported constant with it.

Could this use a literal (0xe000) or a uapi-safe form such as __GENMASK()? Another option is to move the mask into include/linux/mdio.h.

Quoted 2 lines
include/uapi/linux/mdio.h +2 -0
+#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0 /* Template Normal */
+#define MDIO_PMA_10GBT_TESTMODE_1 0x1 /* Template TestMode1 */

[ ... ]

Quoted 23 lines
drivers/net/phy/phy-c45.c +16 -0
@@ -1408,6 +1408,29 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable)
 }
 EXPORT_SYMBOL_GPL(genphy_c45_fast_retrain);
 
+/**
+ * genphy_c45_template_testmode - configure template testmode registers
+ * @phydev: target phy_device struct
+ * @test_mode: testmode includes Normal to Test mode 7
+ *
+ * Description: Set template testmode include Normal to Test mode 7
+ *
+ * Return: 0 on success, or a negative error code on failure (e.g. register
+ * read/write error).
+ */
+int genphy_c45_template_testmode(struct phy_device *phydev, u16 test_mode)
+{
+	u16 ctrl;
+
+	if (test_mode > MDIO_PMA_10GBT_TESTMODE_7)
+		return -EOPNOTSUPP;

drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1436

Quoted 10 lines
drivers/net/phy/phy-c45.c +7 -0
+
+	ctrl = FIELD_PREP(MDIO_PMA_10GBT_TESTMODE_MASK, test_mode);
+	return phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TESTMODE,
+			      MDIO_PMA_10GBT_TESTMODE_MASK, ctrl);
+}
+EXPORT_SYMBOL_GPL(genphy_c45_template_testmode);
+
 /**
  * genphy_c45_plca_get_cfg - get PLCA configuration from standard registers
  * @phydev: target phy_device struct

[Severity: Low]
Where does the term "Template" come from? IEEE 802.3 calls register 1.132 the 10GBASE-T test mode register, and bits 15:13 are the test mode control field. "Template" is not part of either name. Is it taken from the Motorcomm datasheet?

The genphy_c45_* helpers and the uapi mdio.h definitions are generic and should follow the naming in the standard. A vendor term here could make other driver authors think the standard has a separate "template" test mode.

The new defines already leave the term out (MDIO_PMA_10GBT_TESTMODE, MDIO_PMA_10GBT_TESTMODE_MASK). Only the function name, its kernel-doc and the uapi section comment use it, which is also inconsistent.

Would a name like genphy_c45_pma_10gbt_test_mode() work for you? The kernel-doc, the mdio.h comment ("PMA 10GBASE-T test mode register") and the commit subject could be updated to match.

[Severity: Low]
Is -EOPNOTSUPP the right error code here? A test_mode above MDIO_PMA_10GBT_TESTMODE_7 means the caller passed a bad argument. It doesn't mean the operation is unsupported, so -EINVAL seems to fit better.

genphy_c45_template_testmode() is an exported genphy helper, and PHY drivers will usually return its value unchanged to their caller. By convention, -EOPNOTSUPP means the PHY doesn't implement the operation. Code further up may then report the feature as unsupported or fall back to something else. It would not tell the user that the requested mode was out of range.

Could the out-of-range case return -EINVAL instead? -EOPNOTSUPP could then be kept for a PHY that really lacks register 1.132, if you plan to check for that.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930194513.663575-1-kyle.switch%40motor-comm.com
#9 lore raw
In reply to Kyle Switch
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Critical: 0 · High: 2 · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] In yt8824_config_utp_init_paged() (drivers/net/phy/motorcomm.c), U0 TX channels CH0-CH3 are put into reset and never released.
- [High] net: phy: motorcomm: missing phy_package_init_once in yt8824_config_init disrupts active ports
- [Medium] In yt8824_config_utp_init_paged(), the '100M template amplitude' write to YT8824_DAC_IMID_CH2_CH3_CFG_ORG_REG (0x46e) has a…
- [Medium] yt8824_read_status_paged() sets phydev->speed = SPEED_UNKNOWN and phydev->duplex = DUPLEX_UNKNOWN whenever the link is down (lines…
- [Medium] yt8824_sds_isolate_and_softreset_paged() (lines 1060-1078) and yt8824_extern_config_sds_init_paged() hold the bus-wide MDIO mutex…
- [Low] yt8824_read_status_paged() calls genphy_c45_read_lpa() only when autoneg is enabled and complete (line 4602).
- [Low] In yt8824_probe(), phy_package_probe_once() sets the package 'probed' bit through test_and_set_bit() before…

--

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

This adds support for the Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver. The driver uses the phy_package helpers to reach the shared top extended register space. A package-wide mutex serializes the UTP/SerDes space switching between the four ports.

Quoted 4 lines
drivers/net/phy/motorcomm.c +0 -0
index 90a4f86f2758b..dfa0612d713cb 100644

[ ... ]

Quoted 1 line
drivers/net/phy/motorcomm.c +0 -0
@@ -626,11 +935,1125 @@ static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)

[ ... ]

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+static int yt8824_sds_isolate_and_softreset_paged(struct phy_device *phydev)
+{
+	int old_page = YT8824_RSSR_UTP_SPACE;
+	int val = 0;
+	int ret = -1;
+
+	old_page = phy_select_page(phydev, YT8824_RSSR_SERDES_SPACE);
+	if (old_page < 0)
+		goto err_restore_page;
+

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

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+	/* sds softreset and disable isolate */
+	ret = __phy_modify(phydev, MII_BMCR, BMCR_RESET | BMCR_ISOLATE,
+			   BMCR_RESET & ~BMCR_ISOLATE);
+	if (ret < 0)
+		goto err_restore_page;
+
+	/* poll while still holding the lock */
+	ret = read_poll_timeout(__phy_read, val,
+				(val < 0) || !(val & BMCR_RESET), 50000, 600000,
+				true, phydev, MII_BMCR);

[Severity: Medium]
phy_select_page() takes the bus-wide mii_bus->mdio_lock and phy_restore_page() releases it. That means this read_poll_timeout() sleeps with the bus lock held. Because sleep_before_read is true, each call holds it for at least 50ms and up to 600ms.

Is it ok to hold the global MDIO lock that long?

In 10G-QXGMII mode this path runs from soft_reset, suspend, resume and the error restore paths, for each of the four ports. phy_init_hw() calls .soft_reset and then .config_init, and yt8824_config_init() calls yt8824_soft_reset() again. So a single port init goes through several of these windows.

yt8824_extern_config_sds_init_paged() does the same thing. It holds the lock across the whole SerDes init sequence and then runs another sleeping BMCR_RESET poll at the end.

While the lock is held, the sibling ports' phy_state_machine() work, PHYs in other packages and any switch on the same bus are all blocked. That can in turn stall ethtool/RTNL users waiting on those phydev locks.

phy_read_poll_timeout() drops the bus lock between polls to avoid this. Here that is harder, because the UTP/SerDes space select lives in the package-common top-ext register.

Quoted 6 lines
drivers/net/phy/motorcomm.c +6 -0
+	if (val < 0)
+		ret = val;
+
+err_restore_page:
+	return phy_restore_page(phydev, old_page, ret);
+}

[ ... ]

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

[ ... ]

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

Quoted 4 lines
drivers/net/phy/motorcomm.c +4 -0
+	/* 100M template amplitude */
+	ctrl = FIELD_PREP(YT8824_DAC_IMID_CH3_ORG, 0x45);
+	ctrl |= FIELD_PREP(YT8824_DAC_IMID_CH2_ORG, 0x45);
+	mask = YT8824_DAC_IMID_CH3_ORG | YT8824_DAC_IMID_CH3_ORG;
                                          ^^^^

[Severity: Medium]
Should the second term be YT8824_DAC_IMID_CH2_ORG?

ytphy_modify_ext() goes through __phy_modify(), which writes (old & ~mask) | set. With CH2 left out of the mask, the CH2 field of YT8824_DAC_IMID_CH2_CH3_CFG_ORG_REG becomes old | 0x45 instead of 0x45.

The three sibling writes to 0x46f, 0x470 and 0x471 include both fields in the mask.

Quoted 5 lines
drivers/net/phy/motorcomm.c +5 -0
+	ret = ytphy_modify_ext_with_lock(phydev,
+					 YT8824_DAC_IMID_CH2_CH3_CFG_ORG_REG,
+					 mask, ctrl);
+	if (ret < 0)
+		goto err_restore;

[ ... ]

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

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+	ctrl = FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH0, 0);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH1, 0);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH2, 0);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH3, 0);
+	mask  = YT8824_U0_CSR_RESETB_TX_CH0 | YT8824_U0_CSR_RESETB_TX_CH1 |
+		YT8824_U0_CSR_RESETB_TX_CH2 | YT8824_U0_CSR_RESETB_TX_CH3;
+	ret = ytphy_modify_ext_with_lock(phydev, YT8824_U0_CRS_RESET_REG,
+					 mask, ctrl);
+	if (ret < 0)
+		goto err_restore;

[Severity: High]
Is the SerDes and PLL setup done here really per-port?

yt8824_config_init() runs the whole SerDes sequence in yt8824_extern_config_sds_init_paged() and the UTP sequence in yt8824_config_utp_init_paged() for every PHY in the package. It does this each time phy_init_hw() is called for that PHY:

phy_attach_direct() / mdio_bus_phy_resume()
phy_init_hw()

    yt8824_soft_reset()
    yt8824_config_init()
      yt8824_extern_config_sds_init_paged()
      yt8824_config_utp_init_paged()

In 10G-QXGMII mode all four ports are multiplexed onto one SerDes lane, which is also why the init sets YT8824_CSR_AFE_MANUAL_CTRL_10P3125G.

yt8824_extern_config_sds_init_paged() rewrites the SerDes PLL, LDO and training registers. It restarts calibration through YT8824_RESTART_CAL_CTRL_REG and ends with a BMCR_RESET on the SerDes.

yt8824_config_utp_init_paged() toggles YT8824_PLL_DAC_RST. It also drives the TX RESETB bits in YT8824_U0_CRS_RESET_REG and YT8824_U1_CRS_RESET_REG low before releasing them.

If any of these registers are package-wide rather than per-port, then attaching or resuming one port resets the shared lane, PLL and TX paths. That happens underneath sibling ports that already have link, so their traffic drops until the lane retrains. Many MAC drivers connect the PHY from ndo_open, so a plain ifup on one port is enough to trigger this.

phy_package_init_once() exists for this case. Other multi-port PHY drivers such as mscc and qca807x use it so that only the first port runs the package-global setup.

Could the global part be split into a helper guarded by phy_package_init_once(), leaving only the per-port writes in yt8824_config_init()? Which of the registers touched here are actually shared between the four ports?

If the shared SerDes and PLL must be reprogrammed after the package loses power across suspend, how should that work with the once bit?

[ ... ]

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

Quoted 8 lines
drivers/net/phy/motorcomm.c +8 -0
+	ctrl = FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH0, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH1, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH2, 1);
+	ctrl |= FIELD_PREP(YT8824_U0_CSR_RESETB_TX_CH3, 1);
+	mask = YT8824_U0_CSR_RESETB_TX_CH0 | YT8824_U0_CSR_RESETB_TX_CH1 |
+	       YT8824_U0_CSR_RESETB_TX_CH2 | YT8824_U0_CSR_RESETB_TX_CH3;
+
+	ctrl = FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH0, 1);

[Severity: High]
Is a ytphy_modify_ext_with_lock() call on YT8824_U0_CRS_RESET_REG missing here?

Earlier in yt8824_config_utp_init_paged(), the active-low U0 TX RESETB bits are written to 0. The U0 release value and mask are built here, but ctrl and mask are overwritten by the U1 values straight away. Only YT8824_U1_CRS_RESET_REG is written afterwards.

This means U0 TX channels CH0-CH3 seem to stay in reset, while the function still returns 0.

This path runs on every attach and resume, in both package modes:

phy_init_hw()
yt8824_config_init()

    yt8824_config_utp_init_paged()
Quoted 7 lines
drivers/net/phy/motorcomm.c +7 -0
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH1, 1);
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH2, 1);
+	ctrl |= FIELD_PREP(YT8824_U1_CSR_RESETB_TX_CH3, 1);
+	mask = YT8824_U1_CSR_RESETB_TX_CH0 | YT8824_U1_CSR_RESETB_TX_CH1 |
+	       YT8824_U1_CSR_RESETB_TX_CH2 | YT8824_U1_CSR_RESETB_TX_CH3;
+	ret = ytphy_modify_ext_with_lock(phydev, YT8824_U1_CRS_RESET_REG,
+					 mask, ctrl);

[ ... ]

Quoted 1 line
drivers/net/phy/motorcomm.c +0 -0
@@ -3104,6 +4527,449 @@ static int yt8821_resume(struct phy_device *phydev)

[ ... ]

Quoted 8 lines
drivers/net/phy/motorcomm.c +8 -0
+static int yt8824_read_status_paged(struct phy_device *phydev)
+{
+	int ret;
+	int val;
+
+	ret = phy8824_page_write_with_lock(phydev, YT8824_RSSR_UTP_SPACE);
+	if (ret < 0)
+		return ret;

drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4606

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+
+	ret = genphy_read_status(phydev);
+	if (ret < 0)
+		return ret;
+
+	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
+		ret = genphy_c45_read_lpa(phydev);
+		if (ret < 0)
+			return ret;
+	}

[Severity: Low]
When autoneg is enabled but not complete (link down or renegotiation pending), genphy_c45_read_lpa() is skipped. genphy_read_status() then calls genphy_read_lpa(), which only clears the clause 22 partner bits:

drivers/net/phy/phy_device.c:genphy_read_lpa() {
    ...
	if (phydev->autoneg == AUTONEG_ENABLE) {
		if (!phydev->autoneg_complete) {
			mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising,
							0);
			mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
			return 0;
		}
    ...
}

Could a 2500baseT_Full bit from an earlier 2.5G negotiation stay in phydev->lp_advertising and keep showing up in ethtool?

Other 2.5G drivers such as rtl822x_read_status() clear it explicitly with mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, 0). The existing yt8821_read_status() has the same pattern.

drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4610

Quoted 4 lines
drivers/net/phy/motorcomm.c +4 -0
+
+	if (!phydev->link) {
+		phydev->speed = SPEED_UNKNOWN;
+		phydev->duplex = DUPLEX_UNKNOWN;

[Severity: Medium]
Does this lose a forced speed/duplex when autoneg is disabled?

With AUTONEG_DISABLE, phylib keeps the user's forced setting only in phydev->speed and phydev->duplex. genphy_read_status() has just restored them from BMCR via genphy_read_status_fixed(). After one link-down poll they are replaced with SPEED_UNKNOWN and DUPLEX_UNKNOWN.

On the next ifdown/ifup or resume:

phy_start() / mdio_bus_phy_resume()
_phy_start_aneg()
phy_sanitize_settings()
phy_caps_lookup(SPEED_UNKNOWN, DUPLEX_UNKNOWN, supported, false)

No capability matches speed -1, so phy_caps_lookup() returns the slowest supported mode. Then yt8824_config_aneg()->__genphy_config_aneg() takes the speed < SPEED_1000 path, and genphy_setup_forced() programs 10Mb/s instead of the forced 100/1000/2500.

genphy_read_status() and yt8821_read_status() leave the forced values alone in this case.

Quoted 4 lines
drivers/net/phy/motorcomm.c +4 -0
+		if (phydev->autoneg == AUTONEG_ENABLE)
+			phy_resolve_aneg_pause(phydev);
+		return 0;
+	}

[ ... ]

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+static int yt8824_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct yt8824_shared_priv *shared_priv;
+	int ret;
+
+	ret = devm_of_phy_package_join(dev, phydev, sizeof(*shared_priv));
+	if (ret)
+		return ret;
+

drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4968

Quoted 10 lines
drivers/net/phy/motorcomm.c +10 -0
+	/* Ensure other PHY probes wait for shared mutex initialization. */
+	phy_package_lock(phydev);
+	if (phy_package_probe_once(phydev)) {
+		ret = yt8824_phy_package_probe_once(phydev);
+		if (ret) {
+			phy_package_unlock(phydev);
+			return ret;
+		}
+	}
+	phy_package_unlock(phydev);

[Severity: Low]
This may not be reachable in practice. phy_package_probe_once() sets the package once bit with test_and_set_bit() before the DT parsing in yt8824_phy_package_probe_once(), which can fail. The bit is not cleared again on failure.

If another package member had already joined at that point, it would skip the init and probe successfully with the default PHY_INTERFACE_MODE_INTERNAL. It would not fail on the missing or unsupported motorcomm,package-mode.

However, phy_driver_register() sets PROBE_FORCE_SYNCHRONOUS. With sequential probing, the failing PHY's devres release calls phy_package_leave(), the refcount drops to zero and the shared struct is freed, once bit included. The next joiner then starts fresh.

The !priv || !np check in yt8824_phy_package_probe_once() also looks unreachable. of_phy_package_join() always sets shared->np, and priv is allocated because priv_size is non-zero.

Would it be cleaner to validate the DT property before consuming the once bit, or is the current ordering fine given synchronous probing?

Quoted 3 lines
drivers/net/phy/motorcomm.c +3 -0
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930194513.663575-1-kyle.switch%40motor-comm.com
maintainer
#10 lore raw
In reply to Kyle Switch

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

Quoted 5 lines
drivers/net/phy/motorcomm.c +5 -0
+static int yt8824_config_utp_init_paged(struct phy_device *phydev)
+{
+	/* enable nibble */
+	ctrl = FIELD_PREP(YT8824_U0_U1_ENABEL_ODD_PREAMBLE, 3);
+	mask = YT8824_U0_U1_ENABEL_ODD_PREAMBLE;

ENABLE.

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

Quoted 3 lines
drivers/net/phy/motorcomm.c +3 -0
+	/* 2.5G template tone */
+	ctrl = FIELD_PREP(YT8824_POWER_SAVIE, 0x83);
+	mask = YT8824_POWER_SAVIE;

Is this meant to be SAVE?

Andrew

#11 lore raw
Quoted 11 lines · Andrew Lunn

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

Quoted 5 lines
drivers/net/phy/motorcomm.c +5 -0
+static int yt8824_config_utp_init_paged(struct phy_device *phydev)
+{
+	/* enable nibble */
+	ctrl = FIELD_PREP(YT8824_U0_U1_ENABEL_ODD_PREAMBLE, 3);
+	mask = YT8824_U0_U1_ENABEL_ODD_PREAMBLE;

ENABLE.

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

Quoted 3 lines
drivers/net/phy/motorcomm.c +3 -0
+	/* 2.5G template tone */
+	ctrl = FIELD_PREP(YT8824_POWER_SAVIE, 0x83);
+	mask = YT8824_POWER_SAVIE;

Is this meant to be SAVE?

yes. sorry for the spelling mistakes. In the next version, I'll check the spelling

of all macros added earlier.

Quoted 2 lines

Andrew