net: phy: Add driver for Motorcomm Quad 2.5GbE phy
Subsystems (5)
v29 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 v29
1) Add allOf/if-then constraints to the binding so reg is validated against motorcomm,package-mode, instead of only being described in prose.
2) Optimize the commit message for patch1.
3) Remove GENMASK() in uapi/linux/mdio.h and replace it with plain hex.
4) Rename genphy_c45_template_testmode() to genphy_c45_pma_test_mode().
5) Modify the PHY8824 register layout.
6) Add utp_shared_initialized to track whether the UTP shared register initialization has completed.
7) Add package_validated to indicate whether package initialization has actually completed.
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 | 100 + MAINTAINERS | 2 + drivers/net/phy/Kconfig | 4 +- drivers/net/phy/motorcomm.c | 2110 ++++++++++++++++- drivers/net/phy/phy-c45.c | 20 + include/linux/phy.h | 1 + include/uapi/linux/mdio.h | 12 + 7 files changed, 2246 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Signature · 1 line
2.25.1
PATCH RESEND v29 1/3 dt-bindings: net: Document Motorcomm YT8824 PHY package
Add Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml describing the Motorcomm YT8824, a PHY package containing four PHYs, built on top of ethernet-phy-package.yaml.
The binding introduces a new vendor property, motorcomm,package-mode, to describe whether the package operates in internal or external mode. This is new DT ABI.
The binding also specifies that the package reg property gives the address of the shared top extended register block, which is different from the usual ethernet-phy-package.yaml convention where reg is the first member PHY's address.
In addition, add a new M: entry for Kyle Switch to the existing MOTORCOMM PHY DRIVER section in MAINTAINERS, and list the new binding in that section's F: entries. Note that this makes Kyle a maintainer of all existing Motorcomm PHY code (drivers/net/phy/motorcomm.c and motorcomm,yt8xxx.yaml), not only the new binding.
--- .../bindings/net/motorcomm,yt8824.yaml | 100 ++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 102 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +100 -0
@@ -0,0 +1,100 @@ +# 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. The member PHYs are + fixed at MDIO addresses 4..7 and the shared top + extended register block is at address 9. + - 10g-qxgmii: YT8824 is a standalone external PHY, + connected via 10G QXGMII. The member PHYs start at + the base MDIO address and the shared top extended + register block is at base + 4. + $ref: /schemas/types.yaml#/definitions/string + enum: [ internal, 10g-qxgmii ] + + reg: + description: + The absolute MDIO address of the YT8824 shared top extended + 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 + +allOf: + - if: + properties: + motorcomm,package-mode: + const: internal + then: + properties: + reg: + const: 9 + - if: + properties: + motorcomm,package-mode: + const: 10g-qxgmii + then: + properties: + reg: + const: 4 + +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
@@ -18927,8 +18927,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
[email protected]
AI reviewRe: [PATCH net-next v29 RESEND 1/3] dt-bindings: net: Document Motorcomm YT8824 PHY package
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] dt-bindings: net: motorcomm,yt8824 hardcodes reg to 4 in 10g-qxgmii mode - [Low] dt-bindings: net…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] dt-bindings: net: motorcomm,yt8824 hardcodes reg to 4 in 10g-qxgmii mode
- [Low] dt-bindings: net: non-canonical property ordering in motorcomm,yt8824.yaml
--
commit a6fe4858104e023d2f9d8f0b8962a9e062f5996e
Author: Kyle Switch <[email protected]>
dt-bindings: net: Document Motorcomm YT8824 PHY package
This commit adds the Device Tree binding schema for the Motorcomm YT8824 quad Ethernet PHY package and updates MAINTAINERS.
Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +0
-0@@ -0,0 +1,100 @@
[ ... ]
Quoted 40 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +40
-0+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. The member PHYs are + fixed at MDIO addresses 4..7 and the shared top + extended register block is at address 9. + - 10g-qxgmii: YT8824 is a standalone external PHY, + connected via 10G QXGMII. The member PHYs start at + the base MDIO address and the shared top extended + register block is at base + 4. + $ref: /schemas/types.yaml#/definitions/string + enum: [ internal, 10g-qxgmii ] + + reg: + description: + The absolute MDIO address of the YT8824 shared top extended + 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 + +allOf: + - if: + properties: + motorcomm,package-mode: + const: internal + then: + properties:
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 66
Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10
-0+ reg: + const: 9 + - if: + properties: + motorcomm,package-mode: + const: 10g-qxgmii + then: + properties: + reg: + const: 4
[Severity: Medium]
Does constraining reg to const: 4 when motorcomm,package-mode is 10g-qxgmii reject valid non-zero base MDIO addresses during dtbs_check?
The descriptions of motorcomm,package-mode and reg state that in external 10g-qxgmii mode, reg is the base MDIO address plus 4 and that a base of 0x0 is only typical rather than fixed.
Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +6
-0+ +unevaluatedProperties: false + +examples: + - | + mdio {
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 82
Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10
-0+ #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";
[Severity: Low]
As reported by Conor Dooley on v21 [1], the property ordering here does not follow canonical DT schema conventions: reg should precede the vendor-specific motorcomm,package-mode property in both properties and required, and compatible and reg should come before #address-cells and #size-cells in the ethernet-phy-package@9 example node.
[1] https://lore.kernel.org/r/20260924-vowed-roulette-abda42cec444@spud
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net-next v29 RESEND 1/3] dt-bindings: net: Document Motorcomm YT8824 PHY package
In reply to Kyle SwitchThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml contradicts itself about the package reg in 10g-qxgmii (external) mode.
- [Low] The commit message says the new motorcomm,package-mode property describes 'whether the package operates in internal or external mode',…
- [Low] motorcomm,yt8824.yaml says the hardware fixes the member PHY MDIO
addresses: 4..7 in internal mode (lines 25-28), and base..base+3…
--
dt-bindings: net: Document Motorcomm YT8824 PHY package
This commit adds a devicetree binding for the Motorcomm YT8824, a package of four PHYs built on top of ethernet-phy-package.yaml. It adds a new motorcomm,package-mode property and defines the package reg as the address of the shared top extended register block. It also adds a maintainer and the new binding file to the MOTORCOMM PHY DRIVER section in MAINTAINERS.
Quoted 6 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +0
-0@@ -0,0 +1,100 @@
[ ... ]
Quoted 12 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +12
-0+ 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. The member PHYs are + fixed at MDIO addresses 4..7 and the shared top + extended register block is at address 9. + - 10g-qxgmii: YT8824 is a standalone external PHY, + connected via 10G QXGMII. The member PHYs start at + the base MDIO address and the shared top extended + register block is at base + 4. + $ref: /schemas/types.yaml#/definitions/string
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 43
Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10
-0+ enum: [ internal, 10g-qxgmii ] + + reg: + description: + The absolute MDIO address of the YT8824 shared top extended + 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]
This isn't a bug, but the wording here doesn't match the enum. The commit message says the property is meant:
"to describe whether the package operates in internal or external mode."
This reg description also says "For external mode". The enum values are internal and 10g-qxgmii, so there is no external value.
The driver later in the series checks these strings against phy_modes() in yt8824_phy_package_probe_once():
} else if (phy_mode_check(mode, PHY_INTERFACE_MODE_10G_QXGMII)) {
package_mode = PHY_INTERFACE_MODE_10G_QXGMII;So the property looks like a host interface selector, not an internal/external switch. Could the commit message and the reg description say that, or say 10g-qxgmii mode instead of external mode?
Quoted 5 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +5
-0+ +required: + - compatible + - motorcomm,package-mode + - reg
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 58
Quoted 10 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +10
-0+ +allOf: + - if: + properties: + motorcomm,package-mode: + const: internal + then: + properties: + reg: + const: 9
[Severity: Low]
The mode description says the member PHYs are fixed at MDIO addresses 4..7 in internal mode. In 10g-qxgmii mode they are at base..base+3, which is reg - 4 .. reg - 1. Should the schema also constrain the child ethernet-phy@N nodes?
The children only get the generic pattern from ethernet-phy-package.yaml:
patternProperties:
^ethernet-phy@[a-f0-9]+$:
$ref: ethernet-phy.yaml#
As a result, an internal mode DT with member PHYs at 0..3 or 10..13 still passes dt_binding_check.
realtek,rtl8224-package.yaml uses the same base schema and limits the child reg range relative to the package reg:
- if:
properties:
reg: { const: 4 }
then:
patternProperties:
"^ethernet-phy@[a-f0-9]+$":
properties:
reg: { minimum: 4, maximum: 7 }Would a similar per-mode child reg constraint work here?
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml line 66
Quoted 8 lines
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +8
-0+ - if: + properties: + motorcomm,package-mode: + const: 10g-qxgmii + then: + properties: + reg: + const: 4
[Severity: Medium]
Does this conditional match the reg description above? The mode description says that in 10g-qxgmii mode the member PHYs start at a base MDIO address and the top block is at base + 4. The reg description adds "where base is typically 0x0". With reg pinned to const 4, only base 0 passes dt_binding_check and dtbs_check.
Some boards may put a standalone YT8824 at a non-zero base. Two examples are members at 8..11 with the top block at 12, or two YT8824 packages on one MDIO bus. The schema would reject these, even though the text describes that layout as valid.
The only way to get such a DT to validate would be to write reg = <4>. But the driver later in the series uses the package reg directly as the top block address. Both ytphy_read_top_ext() and ytphy_write_top_ext() do this:
drivers/net/phy/motorcomm.c:ytphy_read_top_ext() {
...
ret = __phy_package_write(phydev, 0, YTPHY_PAGE_SELECT, regnum);
...
return __phy_package_read(phydev, 0, YTPHY_PAGE_DATA);
}With that workaround, every shared top block access would go to the wrong MDIO address.
If the hardware always puts the external base at 0, should the "typically" and "base + 4" text be changed? If not, could the constraint be relaxed, for example to minimum: 4 and maximum: 31?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202105259.3767612-1-kyle.switch%40motor-comm.com
PATCH RESEND v29 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 | 20 ++++++++++++++++++++ include/linux/phy.h | 1 + include/uapi/linux/mdio.h | 12 ++++++++++++ 3 files changed, 33 insertions(+)
drivers/net/phy/phy-c45.c +20 -0
@@ -1444,6 +1444,26 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) }EXPORT_SYMBOL_GPL (genphy_c45_fast_retrain); +/** +* genphy_c45_pma_test_mode - configure the 10GBASE-T PMA test mode register +* @phydev: target phy_device struct +* @test_mode: test mode to select, one of MDIO_PMA_10GBT_TESTMODE_* +* +* Set the 10GBASE-T PMA test mode to Normal or one of Test Mode 1..7. +* +* Return: 0 on success, or a negative error code on failure (e.g. register +* read/write error). +*/ +int genphy_c45_pma_test_mode (struct phy_device *phydev,u16 test_mode) +{ +if (test_mode & ~MDIO_PMA_10GBT_TESTMODE_MASK ) +return -EOPNOTSUPP ; + +return phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,MDIO_PMA_10GBT_TESTMODE , +MDIO_PMA_10GBT_TESTMODE_MASK , test_mode); +} +EXPORT_SYMBOL_GPL (genphy_c45_pma_test_mode); +/** * genphy_c45_plca_get_cfg - get PLCA configuration from standard registers * @phydev: target phy_device struct
include/linux/phy.h +1 -0
@@ -2368,6 +2368,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_pma_test_mode (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 test mode register */ +#define MDIO_PMA_10GBT_TESTMODE_MASK 0xE000/* Test mode control */ +#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0000/* Normal */ +#define MDIO_PMA_10GBT_TESTMODE_1 0x2000/* Test Mode 1 */ +#define MDIO_PMA_10GBT_TESTMODE_2 0x4000/* Test Mode 2 */ +#define MDIO_PMA_10GBT_TESTMODE_3 0x6000/* Test Mode 3 */ +#define MDIO_PMA_10GBT_TESTMODE_4 0x8000/* Test Mode 4 */ +#define MDIO_PMA_10GBT_TESTMODE_5 0xA000/* Test Mode 5 */ +#define MDIO_PMA_10GBT_TESTMODE_6 0xC000/* Test Mode 6 */ +#define MDIO_PMA_10GBT_TESTMODE_7 0xE000/* Test Mode 7 */ +/* PCS 10GBASE-R/-T status register 1. */ #define MDIO_PCS_10GBRT_STAT1_BLKLK 0x0001/* Block lock attained */
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v29 RESEND 2/3] net: phy: Add support for Template Control register for PMA
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 commit subject ("net: phy: Add support for Template Control register for PMA") and body ("10GBASE-T PMA Template Test Mode…
- [Low] genphy_c45_pma_test_mode() in drivers/net/phy/phy-c45.c is documented to select "Normal or one of Test Mode 1..7", but it only…
--
net: phy: Add support for Template Control register for PMA
This commit adds a genphy_c45_pma_test_mode() helper and uAPI defines for the 10GBASE-T PMA test mode register (1.132). The helper selects Normal or Test Mode 1..7 by programming bits 15:13 of that register.
Quoted 5 lines
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.
[Severity: Low]
This isn't a bug, but is "Template" the right name for this register?
IEEE 802.3 calls register 1.132 the 10GBASE-T test mode register. The code in this patch uses the same name:
#define MDIO_PMA_10GBT_TESTMODE 132 /* Test mode control */
The kernel-doc for genphy_c45_pma_test_mode() also says "configure the 10GBASE-T PMA test mode register".
Could the subject and body use the test mode name instead?
Quoted 15 lines
drivers/net/phy/phy-c45.c +7
-0@@ -1444,6 +1444,26 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) }EXPORT_SYMBOL_GPL (genphy_c45_fast_retrain); +/** +* genphy_c45_pma_test_mode - configure the 10GBASE-T PMA test mode register +* @phydev: target phy_device struct +* @test_mode: test mode to select, one of MDIO_PMA_10GBT_TESTMODE_* +* +* Set the 10GBASE-T PMA test mode to Normal or one of Test Mode 1..7. +*
drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1463
Quoted 10 lines
drivers/net/phy/phy-c45.c +10
-0+* Return: 0 on success, or a negative error code on failure (e.g. register +* read/write error). +*/ +int genphy_c45_pma_test_mode (struct phy_device *phydev,u16 test_mode) +{ +if (test_mode & ~MDIO_PMA_10GBT_TESTMODE_MASK ) +return -EOPNOTSUPP ; + +return phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,MDIO_PMA_10GBT_TESTMODE , +MDIO_PMA_10GBT_TESTMODE_MASK , test_mode);
[Severity: Low]
The kernel-doc says this selects "Normal or one of Test Mode 1..7". The helper only writes bits 15:13 of register 1.132, because MDIO_PMA_10GBT_TESTMODE_MASK is 0xE000.
In IEEE 802.3, bits 1.132.12:10 are the transmitter test frequencies field. That field picks the dual-tone pair sent in Test Mode 4. Several of its encodings are reserved, including 000.
What happens when a caller passes MDIO_PMA_10GBT_TESTMODE_4? The read-modify-write keeps whatever is already in bits 12:10. Frequency bits cannot be passed in either, because the check above rejects them:
if (test_mode & ~MDIO_PMA_10GBT_TESTMODE_MASK) return -EOPNOTSUPP;
The PHY would then send whatever tone pair the stale bits select. That could be a reserved encoding, depending on the PHY's reset value.
The uAPI header also defines MDIO_PMA_10GBT_TESTMODE_4 but nothing for bits 12:10.
The only caller in this series is the YT8824 code in drivers/net/phy/motorcomm.c, added by "net: phy: Add driver for Motorcomm Quad 2.5GbE phy". It only uses MDIO_PMA_10GBT_TESTMODE_1 and MDIO_PMA_10GBT_TESTMODE_NORMAL, so nothing in the tree triggers this today.
Could the kernel-doc say that Test Mode 4 needs the frequency field programmed separately? Alternatively, could the header gain defines for bits 12:10, with a way to pass them through this exported helper?
Quoted 3 lines
drivers/net/phy/phy-c45.c +3
-0+} +EXPORT_SYMBOL_GPL (genphy_c45_pma_test_mode); +
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202105259.3767612-1-kyle.switch%40motor-comm.com
PATCH RESEND v29 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 | 2110 ++++++++++++++++++++++++++++++++++- 2 files changed, 2111 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 +2108 -2
2,188 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 10 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · Low: 5
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).
- [Medium] The split between per-UTP and pair-shared register writes does not match the kernel-doc.
- [Medium] priv->sds_initialized and priv->utp_shared_initialized[] live in the phy_package shared priv and are cleared only in…
- [Medium] yt8824_sds_isolate_and_softreset_paged() and yt8824_extern_sds_softreset() poll BMCR_RESET with…
- [Medium] yt8824_power_on(), yt8824_power_down() and yt8824_soft_reset() wrap UTP power and reset transitions in PMA TESTMODE_1 and, in QXGMII…
- [Medium] yt8824_config_utp_top_ext_init_paged() asserts the TX channel resets for both UTPs of a pair (U0/U1 CSR_RESETB_TX = 0, starting at…
- [Low] The commit message for a roughly 2100-line driver addition leaves out several behaviours and constraints a maintainer needs.
- [Low] Two comments in the probe path describe retry behaviour the code does not have.
- [Low] yt8824_utp_shared_group() works out the UTP pair from the absolute phydev->mdio.addr against hardcoded bases (0 for QXGMII, 4…
- [Low] Some comments in struct yt8824_shared_priv do not match the code.
- [Low] yt8824_phy_package_probe_once() calls mutex_init(&priv->shared_lock) on package-shared memory, and nothing…
--
net: phy: Add driver for Motorcomm Quad 2.5GbE phy
This adds YT8824 quad-port 2.5G PHY support to the Motorcomm PHY driver. It uses the phy_package helpers to coordinate the top extended register space shared by all ports. It also makes MOTORCOMM_PHY select PHY_PACKAGE.
Quoted 3 lines
Add support for Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver, using the
phy_packagehelpers for the shared top extended register space.
[Severity: Low]
This isn't a bug, but could the commit message say more about what is being added? These points are not mentioned:
- There are two package modes, chosen by the motorcomm,package-mode DT
property: internal, with members at MDIO addresses 4..7, and 10g-qxgmii, with members at 0..3.
- The driver only works with DT. yt8824_probe() calls devm_of_phy_package_join(), which returns -EINVAL when there is no of_node or no ethernet-phy-package parent. On a non-DT system the probe fails and genphy gets bound instead.
- yt8824_soft_reset(), yt8824_suspend() and yt8824_resume() wrap each transition in PMA test mode 1 and a SerDes isolate/softreset. The code only says "NOTE: need WA like softreset". What hardware problem does this workaround address?
- MOTORCOMM_PHY now does select PHY_PACKAGE for every Motorcomm PHY user.
- The driver depends on genphy_c45_pma_test_mode().
Quoted 4 lines
drivers/net/phy/motorcomm.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/phy/motorcomm.c +2
-0@@ -415,6 +657,34 @@ struct yt8521_priv {u8 reg_page; }; +struct yt8824_shared_priv { +phy_interface_t package_mode;
[ ... ]
drivers/net/phy/motorcomm.c struct yt8521_priv { · line 678
Quoted 9 lines
drivers/net/phy/motorcomm.c +9
-0+/* +* UTP top ext register space starts at 0xa000. Adjacent UTP pairs share +* one instance (UTP0/UTP1, UTP2/UTP3), so shared registers are +* configured only once per group; this flag tracks whether the group's +* shared registers have been initialized. +* utp_top_ext_init_done[0]: UTP0/UTP1 shared. +* utp_top_ext_init_done[1]: UTP2/UTP3 shared. +*/ +bool utp_shared_initialized[2 ];
[Severity: Low]
This isn't a bug, but the comment refers to utp_top_ext_init_done[], and the field is named utp_shared_initialized[].
The UTP0/UTP1 and UTP2/UTP3 membership is also only right for 10g-qxgmii. In internal mode, yt8824_utp_shared_group() maps the groups to UTP4/UTP5 and UTP6/UTP7:
if (priv->package_mode == PHY_INTERFACE_MODE_INTERNAL) base = 4;
The same applies to the "UTP Top Extended0 (shared by UTP0, UTP1)" lines in the YT8824 register overview comment.
[ ... ]
Quoted 1 line
drivers/net/phy/motorcomm.c +0
-0@@ -649,2595 +983,4350 @@ static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
[ ... ]
Quoted 7 lines
drivers/net/phy/motorcomm.c +7
-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 );
[ ... ]
drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 1120
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+/* For operations on the SerDes address space, the lock must be held +* throughout the entire process to prevent other PHY operations from +* mistakenly switching the address space to UTP, since the four PHYs +* share the bit that switches the address space. +*/ + ret =read_poll_timeout (__phy_read, val, + (val <0 ) || !(val &BMCR_RESET ),50000 ,600000 , + true, phydev,MII_BMCR ); +if (val <0 ) + ret = val;
[Severity: Medium]
Does this keep the bus-wide mdio_lock held for a long time? phy_select_page() takes the MDIO bus lock through phy_save_page(), and the lock stays held until phy_restore_page(). Because sleep_before_read is true and the sleep is 50 ms, each call keeps the bus locked for at least 50 ms and for up to about 600 ms.
yt8824_extern_sds_softreset() polls the same way. Each port goes through several of these waits across config_init, soft_reset, suspend, resume and the restore paths. For that whole time the other YT8824 ports, and any other PHY or switch on the bus, cannot use MDIO.
The sibling ports are already serialized by priv->shared_lock. Is it still necessary to hold mdio_lock across the sleep to protect the space-select bit?
[ ... ]
Quoted 3 lines
drivers/net/phy/motorcomm.c +3
-0+static int yt8824_utp_shared_group (struct yt8824_shared_priv *priv,int addr) +{ +int base;
[ ... ]
drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 1240
Quoted 9 lines
drivers/net/phy/motorcomm.c +9
-0+if (priv->package_mode ==PHY_INTERFACE_MODE_INTERNAL ) + base =4 ; +else + base =0 ; + +if (addr < base || addr >= base +YT8824_UTP_SHARED_GROUPS *2 ) +return -EINVAL ; + +return (addr - base) /2 ;
[Severity: Low]
Should this use the package base address rather than the absolute phydev->mdio.addr? The top-ext accesses in ytphy_read_top_ext() and ytphy_write_top_ext() go through __phy_package_read() and __phy_package_write(), so they are relative to the package base_addr from the DT reg property. This grouping instead assumes the members are always at 0..3 or 4..7.
The motorcomm,yt8824.yaml binding is inconsistent in the same way. Its description of reg in external mode says "the base MDIO address of the four member PHYs plus 4, where base is typically 0x0", but the schema pins reg to const 4 for 10g-qxgmii.
Consider a second YT8824 on the same bus with members at 8..11 and reg = <12>. Here this returns -EINVAL, and yt8824_config_utp_top_ext_init_paged() fails. As a result yt8824_config_init() fails for every port, after the SerDes and per-UTP sequences have already been written.
A schema-valid DT does not hit this today. Should the code and the binding text be brought into agreement?
Quoted 9 lines
+/**
+ *yt8824_config_utp_top_ext_init_paged()- config phy8824 shared UTP top ext
+ * @phydev: targetphy_devicestruct
+ *
+ * Programs the UTP top extended register space shared by adjacent UTP
+ * pairs (UTP0/UTP1, UTP2/UTP3): write protection, PLL calibration,
+ * P0/P1 DAC bias, P01 PLL enable, U0/U1 CSR TX resets and odd-preamble
+ * enable. Runs once per shared group, guarded by
+ * priv->utp_shared_initialized[grp].
[ ... ]
drivers/net/phy/motorcomm.c
Quoted 2 lines
drivers/net/phy/motorcomm.c +1
-0+if (priv->utp_shared_initialized[grp])return 0 ;
[Severity: Medium]
Can these flags become stale after a hardware reset? priv->utp_shared_initialized[] and priv->sds_initialized are cleared only in yt8824_phy_package_probe_once(). The chip can still be reset while the driver stays bound:
phy_detach()
phy_detach_internal()
phy_device_reset(phydev, 1)
On the next attach, phy_init_hw() deasserts reset and calls yt8824_config_init(). This check then returns early. So does the one in yt8824_extern_config_sds_init_paged():
if (priv->sds_initialized) return 0;
Several steps get skipped as a result: the shared PLL/DAC bias programming, the TX reset release, the efuse-derived SerDes trims and the calibration restart. The per-port registers are reprogrammed.
This can happen when the PHY node has reset-gpios, for example with a MAC that calls phylink_disconnect_phy() from ndo_stop. It can also happen if power is lost during suspend.
[ ... ]
drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 1286
Quoted 8 lines
drivers/net/phy/motorcomm.c +8
-0+/* write protecting */ + mask =YT8824_WRITE_PROTECT ; + ctrl =YT8824_WRITE_PROTECT ; + ret =ytphy_modify_ext_with_lock (phydev, +YT8824_WRITE_PROTECT_CAL_REG , + mask, ctrl); +if (ret <0 ) + goto err_restore;
[Severity: Medium]
The kernel-doc above says this function does the odd-preamble enable. That write is actually in yt8824_config_utp_init_paged(), which runs for every port with no group guard:
/* enable nibble */ ctrl = FIELD_PREP(YT8824_U0_U1_ENABLE_ODD_PREAMBLE, 3); mask = YT8824_U0_U1_ENABLE_ODD_PREAMBLE; ret = ytphy_modify_ext_with_lock(phydev, YT8824_IF_CTRL_REG, mask, ctrl);
YT8824_IF_CTRL_REG is 0xa003, which is in the shared top-ext space.
The opposite also happens. YT8824_WRITE_PROTECT_CAL_REG is 0x1. The yt8824_config_utp_init_paged() kernel-doc says that range is private per-UTP ext space, yet the register is written only here, behind the utp_shared_initialized[grp] check. Does the second UTP of each pair end up without its write-protect bit set?
The yt8824_config_utp_init_paged() kernel-doc also says shared registers are configured "according to the UTP index". That function has no index-dependent logic.
[ ... ]
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_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 1435
Quoted 5 lines
drivers/net/phy/motorcomm.c +5
-0+ priv->utp_shared_initialized[grp] = true; +return 0 ; + +err_restore: +return ret;
[Severity: Medium]
Suppose one of the writes after the TX resets are asserted fails. The function jumps to err_restore, which only returns. Doesn't that leave both UTPs of the pair with their transmitters held in reset (U0/U1 CSR_RESETB_TX cleared) and the shared PLL/DAC bias only partly programmed?
utp_shared_initialized[grp] is not set, so a later successful config_init on either port would recover. Until that happens, the sibling port's TX stays in reset even if that port was already configured.
[ ... ]
Quoted 1 line
+static int
yt8824_config_utp_init_paged(struct phy_device *phydev)
[ ... ]
Quoted 3 lines
drivers/net/phy/motorcomm.c +3
-0+ ret =phy_modify (phydev,MII_BMCR ,BMCR_PDOWN ,BMCR_PDOWN ); +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 1815
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+/* reset */ + ret =genphy_c45_pma_test_mode (phydev,MDIO_PMA_10GBT_TESTMODE_1 ); +if (ret <0 ) + goto err_restore_normal; + + ret =phy_modify (phydev,MII_BMCR ,BMCR_PDOWN ,0 ); +if (ret <0 ) + goto err_restore_normal; + ret =phy_modify (phydev,MII_BMCR ,BMCR_RESET |BMCR_ANENABLE , +BMCR_RESET |BMCR_ANENABLE );
[Severity: Medium]yt8824_power_on(), yt8824_power_down() and yt8824_soft_reset() wrap UTP power and reset transitions in PMA test mode 1. For 10g-qxgmii they also wrap them in yt8824_sds_isolate_paged() and yt8824_sds_isolate_and_softreset_paged() ("NOTE: need WA like softreset").
This function sets BMCR_PDOWN with no test mode and no SerDes isolate. The later power-up and BMCR_RESET run under TESTMODE_1, but they still skip the SerDes isolate and softreset. That is true even in 10g-qxgmii mode, where one lane carries all four ports. Is skipping the workaround here intentional?
The yt8824_soft_reset() call at the end of yt8824_config_init() applies the full sequence again. Could these earlier transitions still disturb the shared lane before that runs?
[ ... ]
Quoted 6 lines
drivers/net/phy/motorcomm.c +6
-0+/* +* Validate the DT first and keep the parsed value in a local +* variable. Do not touch the shared state until validation has +* succeeded, so a failure leaves the package untouched and a +* sibling PHY can retry. +*/
[ ... ]
drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 5276
Quoted 2 lines
drivers/net/phy/motorcomm.c +2
-0+/* Validation succeeded, initialize the shared state. */ +mutex_init (&priv->shared_lock);
[Severity: Low]
This isn't a bug, but this mutex has no matching mutex_destroy(). When the last port leaves, phy_package_leave() just calls kfree(shared->priv), and the driver has no .remove. With CONFIG_DEBUG_MUTEXES, the lock's debug state is never torn down before the memory is freed.
[ ... ]
Quoted 8 lines
drivers/net/phy/motorcomm.c +8
-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); + shared_priv->package_validated = ret ? ret :1 ; + }else { +/* +* Another port has already consumed the once bit. Do not assume
drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 5322
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+* its DT validation succeeded; check the result it recorded. +*/ + ret = shared_priv->package_validated; +if (ret ==0 ) { +/* +* Unreachable in practice: once bit consumed but no +* result recorded yet. Retry probe instead of +* proceeding silently. +*/ + ret = -EAGAIN ;
[Severity: Low]
This isn't a bug, but the comments here describe retry behaviour that the code does not have.
The driver core only re-probes on -EPROBE_DEFER, so -EAGAIN makes the probe fail permanently instead of retrying. This branch also cannot be reached, because package_validated is always set under phy_package_lock() before the lock is dropped.
The comment in yt8824_phy_package_probe_once() says a failure "leaves the package untouched and a sibling PHY can retry". But a sibling that joined before the failed port left takes the else branch here and just returns the stored error. Validation only runs again if the shared struct has been freed and allocated again.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202105259.3767612-1-kyle.switch%40motor-comm.com