Skip to content

kernel: rtl8261n: clear PMA_CTRL LPOWER bit on Realtek SoCs - #23386

Closed
carlosz1986 wants to merge 2 commits into
openwrt:mainfrom
carlosz1986:rtl8261n-clear-lpower
Closed

carlosz1986 wants to merge 2 commits into
openwrt:mainfrom
carlosz1986:rtl8261n-clear-lpower

Conversation

@carlosz1986

Copy link
Copy Markdown
Contributor

While working on the Hasivo S1300WP-8XGT-4S, I figured out that the auto-negotiate never starts...
I could get it running by clearing bit 11 (PMA_CTRL) ...

Her is a working branch, for the device - but everything is still pretty hacky and early stage.

main...carlosz1986:openwrt:hasivo_S1300WP-8XGT-4S-plus_clean
And the discussion is here:
https://forum.openwrt.org/t/hasivo-s1300wp-8xgt-4s/233033/62

I would appreciate feedback from the experts :-)
cheers

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

@plappermaul

Copy link
Copy Markdown
Contributor

I'm totally lost regarding all these RTL826x discussion. But PHY does not depend on MACH. So this is wrong (and the last patch too).

To start somewhere: Unconditionally clear the bit in config_init(). That should be needed on all architectures.

@jonasjelonek any issues you came around on SerDes side regarding the low power state?

@carlosz1986

Copy link
Copy Markdown
Contributor Author

I'm totally lost regarding all these RTL826x discussion. But PHY does not depend on MACH. So this is wrong (and the last patch too).

I change the PR to draft, what it actually is ...
the ifdev CONFIG_MACH_REALTEK_RTL is not tested yet, but the phy_clear_bits_mmd actually does the job

@carlosz1986
carlosz1986 marked this pull request as draft May 15, 2026 16:26
@plappermaul

Copy link
Copy Markdown
Contributor

Ok had a look around. The old patch is a mess.

First: The driver should simply use genphy_c45_pma_resume(). See https://elixir.bootlin.com/linux/v6.18.1/source/drivers/net/phy/phy-c45.c#L52 That is a must-have and the part from the old patch can be reverted.

Second: If low power mode "aka genphy_c45_pma_suspend() or rtkphy_c45_suspend()" is not desired on Realtek platform we should work around that with a devicetree quirk. Maybe something like "realtek,disable-pma-low-power" for the time being.

@carlosz1986

Copy link
Copy Markdown
Contributor Author

Thx for fast help @plappermaul , I appreciate it!

First: The driver should simply use genphy_c45_pma_resume(). See https://elixir.bootlin.com/linux/v6.18.1/source/drivers/net/phy/phy-c45.c#L52 That is a must-have and the part from the old patch can be reverted.

So this would replace my part with something like:

ret = genphy_c45_pma_resume(phydev);
if (ret && ret != -EOPNOTSUPP)
   phydev_warn(phydev, "PMA resume failed: %d\n", ret);

The dts config like "realtek,disable-pma-low-power" would only make sense if this change would cause issues on other devices, wouldn't it?

@plappermaul

plappermaul commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Regarding resume:

rtk_phylib_c45_power_normal() and its consumer is basically genphy_c45_pma_resume(). So you can drop these functions completely and just link genphy_c45_pma_resume() in the driver table.

Regarding disabling of suspend() something like this is needed:

static int rtkphy_c45_suspend(struct phy_device *phydev)
{
    struct device *dev = &phydev->mdio.dev
    int ret = 0;

    if (device_property_read_bool(dev, "realtek,disable-pma-low-power"))
        return -EOPNOTSUPP;

    ret = rtk_phylib_c45_power_low(phydev);

    phydev->speed = SPEED_UNKNOWN;
    phydev->duplex = DUPLEX_UNKNOWN;
    phydev->pause = 0;
    phydev->asym_pause = 0;

    return ret;
}

Add the property to the phy in the devicetree and suspend should be deactivated.

@carlosz1986
carlosz1986 force-pushed the rtl8261n-clear-lpower branch from b3424df to a8c563d Compare May 15, 2026 21:45
@carlosz1986
carlosz1986 marked this pull request as ready for review May 15, 2026 21:49
@carlosz1986
carlosz1986 requested a review from openwrt-ai May 15, 2026 21:49
@jonasjelonek

Copy link
Copy Markdown
Member

@jonasjelonek any issues you came around on SerDes side regarding the low power state?

Actually no, when I had to deal with this PHY this issue didn't came up and the SerDes side was mostly working fine. And no apparent issues with other PHYs.

@github-actions github-actions Bot added the kernel pull request/issue with Linux kernel related changes label May 15, 2026

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found.


To address review feedback, force-push fixes to this branch.
Don't close and open a new PR — that loses the review history
and the bot starts from scratch.


Generated by Claude Code

@plappermaul

Copy link
Copy Markdown
Contributor

Looking at mirror/dd-wrt@777419c I anticipate we have some complexer issues on all devices. So please adapt as follows:

  • Patch 1: for better bisectability just adapt the resume part. As said this can run unconditionally
  • Patch 2: I advise to disable PMA as default. So reverse the logic and the devicetree property and name it "realtek,enable-pma-low-power". Write a warning if that is not set. So every consumer outside the Realtek world will notice.

Thanks in advance.

Replace rtkphy_c45_resume() with a direct reference to
genphy_c45_pma_resume() in the driver ops table. The vendor wrapper
rtk_phylib_c45_power_normal() performs a single MMD write that is
bit-identical to the standard kernel helper; drop both the wrapper
and the rtkphy_c45_resume() function it served.

Resume is the safe direction here (clears MDIO_CTRL1_LPOWER) and can
run on all platforms. Commit b77fa45 ("kernel: fix rtl8261n
driver for realtek") previously made resume a no-op on
CONFIG_MACH_REALTEK_RTL, assuming the bootloader had taken the PMA
out of low-power mode itself, which is not true on every Realtek
board (e.g. Hasivo S1300WP-8XGT-4S+).

The suspend path is intentionally left untouched here; a follow-up
patch addresses the broader question of when the PMA-low-power
transition is safe to perform.

Signed-off-by: Carlo Szelinsky <[email protected]>
@carlosz1986
carlosz1986 force-pushed the rtl8261n-clear-lpower branch from a8c563d to f140bff Compare May 16, 2026 08:27
@carlosz1986

Copy link
Copy Markdown
Contributor Author

Thanks in advance.

I have to thank you :-) It was super helpful! I pushed the required changes...

@plappermaul plappermaul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit left.

@carlosz1986
carlosz1986 force-pushed the rtl8261n-clear-lpower branch 2 times, most recently from 31b4adc to e20c692 Compare May 16, 2026 08:55
PMA-low-power suspend on the rtl8261n family has been reported to
leave the PHY unrecoverable on platforms outside the Realtek world
as well, not just on Realtek SoCs. The previous OpenWrt mitigation
(commit b77fa45 "kernel: fix rtl8261n driver for realtek")
only gated the suspend on CONFIG_MACH_REALTEK_RTL, which leaves
every other platform exposed.

Reverse the default: skip the PMA-low-power suspend unless the PHY
node carries the new boolean property "realtek,enable-pma-low-power".
Emit a per-PHY warning at probe when the property is absent, so
board maintainers see the prompt to verify suspend/resume on their
hardware and opt in.

Once verified, a board sets the property on its PHY nodes; the
suspend callback then runs via the standard genphy_c45_pma_suspend()
helper (bit-identical to the dropped vendor wrapper). The previous
#ifndef CONFIG_MACH_REALTEK_RTL guard and the
rtk_phylib_c45_power_low() vendor wrapper are removed.

The new flag is cached in struct rtk_phy_priv alongside the existing
pnswap-* flags, keeping the DT-property read out of the per-suspend
hot path.

Signed-off-by: Carlo Szelinsky <[email protected]>
@carlosz1986
carlosz1986 force-pushed the rtl8261n-clear-lpower branch from e20c692 to 60e78f5 Compare May 16, 2026 08:56

@plappermaul plappermaul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@carlosz1986
carlosz1986 requested a review from openwrt-ai May 16, 2026 10:15

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 new commits; no new issues found.


Generated by Claude Code

@carlosz1986

Copy link
Copy Markdown
Contributor Author

I close this one, because the change is already in the driver PR itself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel pull request/issue with Linux kernel related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants