net: phy: Add driver for Motorcomm Quad 2.5GbE phy
Subsystems (5)
v28 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 v28:
1) Rebase.
changes in v27:
1) Remove unuse macros and "," after yt8824_read_page() and yt8824_write_page().
2) Modify the function description for yt8824_restore_working_status() and yt8824_config_init().
3) Add UTP power up operation after init success in yt8824_config_init().
4) Set sds_initialized to 1 in resume.
changes in v26:
1) Rebase
changes in v25:
1) Correct the naming of some register name macro definitions used for phy8824 initialization to follow the conventional naming style.
No functional change.
changes in v24:
1) Fix the typo during sds init.
2) Add priv->sds_initialized to indicate whether the SDS extended registers shared by the four channels have been initialized.
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 | 4 +- drivers/net/phy/motorcomm.c | 1935 ++++++++++++++++- drivers/net/phy/phy-c45.c | 23 + include/linux/phy.h | 1 + include/uapi/linux/mdio.h | 12 + 7 files changed, 2052 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Signature · 1 line
2.25.1
PATCH v28 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
@@ -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
@@ -18810,8 +18810,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
PATCH v28 2/3 net: phy: Add support for Template Control register for PMA
In reply to Kyle SwitchAdd 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
@@ -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
@@ -2367,6 +2367,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
@@ -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
Paolo Abeni
maintainerRe: [PATCH net-next v28 2/3] net: phy: Add support for Template Control register for PMA
Quoted 13 lines · Kyle Switch
include/uapi/linux/mdio.h +1
-0@@ -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 */
include/uapi/linux/mdio.h line 325
Quoted 5 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 */
IDK if this has possibly been discussed in previous revisions, but uAPI should not use GENMASK(). The plain hex should be preferable.
/P> +#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0 /* Template Normal */
Quoted 11 lines
include/uapi/linux/mdio.h +8
-0+#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 */
PATCH v28 3/3 net: phy: Add driver for Motorcomm Quad 2.5GbE phy
In reply to Kyle SwitchAdd 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 | 4 +- drivers/net/phy/motorcomm.c | 1935 ++++++++++++++++++++++++++++++++++- 2 files changed, 1936 insertions(+), 3 deletions(-)
drivers/net/phy/Kconfig +3 -1
@@ -361,10 +361,12 @@ 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, YT861x PHYs - integrated in YT921x switches, and YT8821 2.5Gbps PHYs. + integrated in YT921x switches, YT8821 2.5Gbps PHYs and YT8824 4 * 2.5G + PHYs. config NATIONAL_PHY tristate "National Semiconductor PHYs"
drivers/net/phy/motorcomm.c +1933 -2
2,013 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: phy: motorcomm: broken sds_initialized tracking in yt8824_resume() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: phy: motorcomm: broken sds_initialized tracking in yt8824_resume() --
commit 4e05c00d9c48d262e045a1a6c3ea0d87e1c1718c
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 motorcomm driver, using phy_package helpers to manage the shared top extended register space.
Quoted 4 lines
drivers/net/phy/motorcomm.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/phy/motorcomm.c +0
-0@@ -642,11 +950,1168 @@ static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
[ ... ]
Quoted 39 lines
drivers/net/phy/motorcomm.c +39
-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 { +if (!priv->sds_initialized) { + ret =yt8824_extern_config_sds_init_paged (phydev); +if (ret <0 ) + goto err; + priv->sds_initialized = true; + } +/* +* Configuring the MII registers of the SDS, +* which are private to each channel. +*/ + ret =yt8824_extern_sds_softreset (phydev); +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); + +phydev_dbg (phydev,"%s done, phy addr: %d\n" , __func__, + phydev->mdio.addr); +return ret; +err: +mutex_unlock (&priv->shared_lock); +return ret; +}
[ ... ]
Quoted 1 line
drivers/net/phy/motorcomm.c +0
-0@@ -3240,6 +4705,455 @@ static int yt8821_resume(struct phy_device *phydev)
[ ... ]
drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4946
Quoted 13 lines
drivers/net/phy/motorcomm.c +13
-0+static int yt8824_resume (struct phy_device *phydev) +{ +struct yt8824_shared_priv *priv =phy_package_get_priv (phydev); +int ret; + +mutex_lock (&priv->shared_lock); + ret =yt8824_power_on (phydev); +if (!ret) + priv->sds_initialized = false; +mutex_unlock (&priv->shared_lock); + +return ret; +}
[Severity: High]
Does clearing priv->sds_initialized in yt8824_resume() cause the shared SerDes to be reset and recalibrated repeatedly as each port in the package is attached or started, while also inverting the initialization order on system resume?
In struct yt8824_shared_priv, sds_initialized is a package-wide flag meant to ensure yt8824_config_init() runs yt8824_extern_config_sds_init_paged() only once for the 4-port package when priv->package_mode is PHY_INTERFACE_MODE_10G_QXGMII.
However, during normal port attachment in phy_attach_direct(), phylib calls phy_init_hw() followed immediately by phy_resume():
drivers/net/phy/phy_device.c:phy_attach_direct() {
...
err = phy_init_hw(phydev);
if (err)
goto error;
if (phydev->mdio.bus->notify_phy_attach) {
err = phydev->mdio.bus->notify_phy_attach(phydev);
if (err)
goto error;
}
phy_resume(phydev);
...
}When the first port is attached, phy_init_hw() -> yt8824_config_init() runs yt8824_extern_config_sds_init_paged() and sets priv->sds_initialized = true, and then phy_resume() -> yt8824_resume() immediately resets priv->sds_initialized = false. Bringing an interface up via phy_start() -> __phy_resume() -> yt8824_resume() also resets priv->sds_initialized = false.
As a result, when each of the remaining three ports in the YT8824 package is attached, priv->sds_initialized is false again, so yt8824_config_init() re-runs yt8824_extern_config_sds_init_paged() on each port. That function asserts the shared SerDes global reset (YT8824_CSR_US_GLB_RESET_N = 0) and restarts SerDes calibration (YT8824_CALIB_SEQ_SW_RST and YT8824_RESTART_CAL_CTRL_REG) while sibling ports in the package are already initialized or active.
Conversely, during system resume in mdio_bus_phy_resume(), phylib calls phy_init_hw() before phy_resume():
drivers/net/phy/phy_device.c:mdio_bus_phy_resume() {
...
ret = phy_init_hw(phydev);
if (ret < 0)
return ret;
ret = phy_resume(phydev);
...
}Because yt8824_suspend() does not clear priv->sds_initialized, if priv->sds_initialized is true prior to suspend, the first port to resume sees priv->sds_initialized == true in yt8824_config_init() (skipping SerDes re-initialization) and only clears priv->sds_initialized = false afterward in yt8824_resume(), causing the second port to re-run package-wide SerDes initialization after the first port has already completed yt8824_config_init().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Paolo Abeni
maintainerThis is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
--- Patch [3]: [PATCH net-next v28 3/3] net: phy: Add driver for Motorcomm Quad 2.5GbE phy --- commit 7395dc0c40b1873da64b3582ad548b846fa382f0
Author: Kyle Switch <[email protected]>
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 phy_package helpers give access to the shared top extended register space, and the four ports share a mutex, the package mode and a SerDes init flag.
Quoted 4 lines
drivers/net/phy/motorcomm.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/phy/motorcomm.c +1
-0@@ -33,6 +39,18 @@* ------------------------------------------------------------ */ +/* YT8824 Register Overview
drivers/net/phy/motorcomm.c line 52
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+* UTP Register space | SERDES Register space +* ------------------------------------------------------------ +* | UTP MII | SERDES MII | +* | UTP MMD | | +* | UTP Extended | SERDES Extended | +* | UTP Top Extended | SERDES Top Extended | +* ------------------------------------------------------------ +* | Common Top Extended | +* ------------------------------------------------------------ +*/
[Severity: Low]
[Finding: main-2-3]
[Sources: opus-5-5]
Is this overview accurate for the SerDes extended registers? It puts "SERDES Extended" among the per-PHY spaces, and only "Common Top Extended" is shown as shared across the package.
yt8824_extern_config_sds_init_paged() writes all of its SerDes tuning registers (PLL VCO/FBDIV, CDR, AFE, DFE, TX pre-emphasis, calibration restart) through the calling PHY's own address:
ytphy_modify_ext() / ytphy_write_ext()
__phy_write(phydev, YTPHY_PAGE_SELECT, regnum)
__mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, ...)
Only the efuse reads go through ytphy_read_top_ext() and the package address. yt8824_config_init() runs this sequence for just one port per package, gated by priv->sds_initialized.
If the SERDES Extended space really is per port, would ports 1-3 never get their SerDes tuning? If it is aliased package-wide, which seems likely with a single QXGMII lane, could the overview say so?
[ ... ]
Quoted 1 line
drivers/net/phy/motorcomm.c +0
-0@@ -642,11 +950,1168 @@ static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
[ ... ]
Quoted 2 lines
drivers/net/phy/motorcomm.c +2
-0+static int yt8824_config_utp_init_paged (struct phy_device *phydev) +{
[ ... ]
Quoted 11 lines
drivers/net/phy/motorcomm.c +11
-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_CSR_RESET_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 1666
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+ ctrl =FIELD_PREP (YT8824_U1_CSR_RESETB_TX_CH0 ,0 ); + ctrl |=FIELD_PREP (YT8824_U1_CSR_RESETB_TX_CH1 ,0 ); + ctrl |=FIELD_PREP (YT8824_U1_CSR_RESETB_TX_CH2 ,0 ); + ctrl |=FIELD_PREP (YT8824_U1_CSR_RESETB_TX_CH3 ,0 ); + 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_CSR_RESET_REG , + mask, ctrl); +if (ret <0 ) + goto err_restore;
[Severity: Medium]
[Finding: main-7-9]
[Sources: opus-5-5]
Are these U0/U1 TX channel resets local to the calling port?
yt8824_config_utp_init_paged() runs from every port's config_init: on each attach, each system resume, and the MII BMCR_RESET ioctl path. There is no phy_package_init_once() or similar guard around it.
Going by their names, several registers written here through the per-port address may cover more than one port:
YT8824_PLL_DAC_RST in 0xa2b6 (toggled 0 then 1) YT8824_U0_CSR_RESET_REG 0xa01d and YT8824_U1_CSR_RESET_REG 0xa01e YT8824_P01_PLL_EN_REG 0xa218
the P0/P1 DAC bias registers 0xa2d5-0xa2d8 YT8824_U0_U1_ENABLE_ODD_PREAMBLE in 0xa003
the PLL VCO registers 0xa20a/0xa20c/0xa20e
The same patch treats 0xa000 (space select) and 0xa13e-0xa140 (efuse) as shared top extended registers, reached through the package address.
If the U0/U1 and P0/P1/P01 registers do cover sibling ports, attaching or resuming one port would briefly hold the neighbouring ports' TX channels and PLL DAC in reset. Wouldn't that drop links that are already up? This is based only on the register names and address range.
[ ... ]
Quoted 17 lines
drivers/net/phy/motorcomm.c +17
-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 { +if (!priv->sds_initialized) { + ret =yt8824_extern_config_sds_init_paged (phydev); +if (ret <0 ) + goto err; + priv->sds_initialized = true; + }
[ ... ]
Quoted 1 line
drivers/net/phy/motorcomm.c +0
-0@@ -3240,6 +4705,455 @@ static int yt8821_resume(struct phy_device *phydev)
[ ... ]
drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4946
Quoted 13 lines
drivers/net/phy/motorcomm.c +13
-0+static int yt8824_resume (struct phy_device *phydev) +{ +struct yt8824_shared_priv *priv =phy_package_get_priv (phydev); +int ret; + +mutex_lock (&priv->shared_lock); + ret =yt8824_power_on (phydev); +if (!ret) + priv->sds_initialized = false; +mutex_unlock (&priv->shared_lock); + +return ret; +}
[Severity: Medium]
[Finding: main-1-1]
[Sources: opus-5-5]
Does clearing sds_initialized here defeat the once-per-package check in yt8824_config_init() above?
phylib calls config_init before resume in each of these paths:
phy_attach_direct()
phy_init_hw() -> yt8824_config_init(), flag set to true
phy_resume() -> yt8824_resume(), flag cleared mdio_bus_phy_resume()
phy_init_hw()
phy_resume() phy_start()
__phy_resume() -> yt8824_resume(), flag cleared
So the flag is false again as soon as port A is attached. The next config_init on any port of the package reruns yt8824_extern_config_sds_init_paged(). That happens on port B attach, and on each port's mdio_bus_phy_resume().
That sequence clears YT8824_CSR_US_GLB_RESET_N and reprograms the PLL VCO/FBDIV/spare registers. It also writes CALIB_SEQ_SW_RST and pulses YT8824_RESTART_CAL_CTRL_REG (0x40, then 0). In 10G-QXGMII mode all four ports share that lane.
Can bringing up one port re-calibrate the SerDes while the sibling ports are carrying traffic?
The opposite case looks possible too. Suppose config_init runs with no resume after it, for example phy_init_hw() from the MII ioctl BMCR_RESET path. The flag then stays true across suspend, and the first config_init after system resume would skip the SerDes init.
In both cases the flag no longer matches the struct comment "true once the package-wide SERDES init has been done".
[ ... ]
Quoted 6 lines
drivers/net/phy/motorcomm.c +6
-0+static int yt8824_phy_package_probe_once (struct phy_device *phydev) +{ +struct yt8824_shared_priv *priv =phy_package_get_priv (phydev); +struct device_node *np =phy_package_get_node (phydev); +const char *mode; +
[ ... ]
Quoted 6 lines
drivers/net/phy/motorcomm.c +6
-0+/* Initialise shared lock for YT8824 */ +mutex_init (&priv->shared_lock); + priv->sds_initialized = false; + priv->package_mode =PHY_INTERFACE_MODE_INTERNAL ; +if (!of_property_read_string (np,"motorcomm,package-mode" , + &mode)) {
[ ... ]
Quoted 4 lines
drivers/net/phy/motorcomm.c +4
-0+ }else { +phydev_err (phydev,"missing package-mode in PHY package node.\n" ); +return -EINVAL ; + }
[ ... ]
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 5152
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]
[Finding: main-4-5]
[Sources: opus-5-5]phy_package_probe_once() uses up the package's once bit before the DT has been validated, and nothing clears it again:
__phy_package_set_once()
return !test_and_set_bit(b, &shared->flags);
yt8824_phy_package_probe_once() also sets package_mode to PHY_INTERFACE_MODE_INTERNAL before it reads "motorcomm,package-mode".
If that property is missing or unsupported, this PHY returns -EINVAL. Its devm_phy_package_leave() only drops its own reference. If a sibling has already joined the package (overlapping probes, for example with async probing), the shared struct survives with the once bit still set.
Would that sibling then see phy_package_probe_once() return false, skip the DT check, and bind in INTERNAL mode, even though the DT is invalid or asks for 10G-QXGMII?
Could a successful package init be tracked in a separate flag under phy_package_lock(), so siblings fail or retry when it isn't set?
The !priv || !np early return can't happen once of_phy_package_join() has succeeded, so an uninitialized shared_lock isn't reachable. The concern is only the unvalidated package mode.
Signature · 1 line
This is an AI-generated review.