net: phy: realtek: SerDes lane polarity and LEDs for RTL8261C/D
Subsystems (4)
cover net: phy: realtek: SerDes lane polarity and LEDs for RTL8261C/D
The RTL8261CE on the Gemtek W1700K (Airoha AN7581) binds, but the 10G ports don't come up: the board routes the USXGMII lanes inverted and the driver never applies tx-polarity/rx-polarity from the device tree. Patch 2 fixes that; the link then comes up at 1G and 10G.
The inversion is done in the PHY because the AN7581 PCS has no known polarity control - nor does its MT7988 XFI T-PHY sibling - and Airoha's own EN8811H driver handles it the same way.
Patch 3 is Chad Monroe's LED support, rebased onto the merged driver with the RTL822X_VND2 LED definitions reused and a polarity bit fix. Patch 1 adds the bindings for both.
Tested on an RTL8261CE (W1700K). Polarity is applied unchanged to the RTL8261C, RTL8261D and RTL8261D_VM, which share config_init() but are untested with inverted lanes. LEDs were also tested on RTL8261C and RTL8261D boards.
The LED callbacks duplicate rtl822xb_led_*(); sharing the code means touching the RTL8221B path, so that is left for a follow-up.
An LLM assistant (Claude) was used for rebasing, restructuring and the changelogs. The register usage comes from existing driver sources and was verified on hardware; the code has been reviewed by me.
Chad Monroe (1):
net: phy: realtek: add LED support for RTL8261C/D
Simon Polack (2):
dt-bindings: net: realtek,rtl82xx: Document RTL8261C/D PHYs
net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
.../bindings/net/realtek,rtl82xx.yaml | 52 ++- drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 402 ++++++++++++++++-- 3 files changed, 427 insertions(+), 28 deletions(-)
base-commit: 8830e65ed46de41f849eefb8ba227d4852c460f6
Signature · 1 line
2.55.0
PATCH 1/3 dt-bindings: net: realtek,rtl82xx: Document RTL8261C/D PHYs
The RTL8261C/D family reports PHY IDs 0x001cc898 (RTL8261C/D), 0x001cc899 (RTL8261CE) and 0x001cc89a (RTL8261D_VM). Add the three corresponding compatible strings.
These parts drive four LEDs from the VEND2 LED register block, so allow the leds node for them the way it is already allowed for the RTL8221B.
They also accept the generic tx-polarity and rx-polarity properties to invert the host-side SerDes lanes, which is needed on boards that route the USXGMII lanes inverted between the SoC and the PHY. Reference phy-common-props.yaml so those properties are described, restrict them to the compatibles that implement them, and add an example using both.
--- .../bindings/net/realtek,rtl82xx.yaml | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +51 -1
@@ -27,6 +27,9 @@ properties: - ethernet-phy-id001c.c862 - ethernet-phy-id001c.c878 - ethernet-phy-id001c.c880 + - ethernet-phy-id001c.c898 + - ethernet-phy-id001c.c899 + - ethernet-phy-id001c.c89a - ethernet-phy-id001c.c910 - ethernet-phy-id001c.c912 - ethernet-phy-id001c.c913
@@ -74,15 +77,35 @@ unevaluatedProperties: false allOf: - $ref: ethernet-phy.yaml# + - $ref: /schemas/phy/phy-common-props.yaml# - if: not: properties: compatible: contains: - const: ethernet-phy-id001c.c916 + enum: + - ethernet-phy-id001c.c898 + - ethernet-phy-id001c.c899 + - ethernet-phy-id001c.c89a + - ethernet-phy-id001c.c916 then: properties: leds: false + - if: + not: + properties: + compatible: + contains: + enum: + - ethernet-phy-id001c.c898 + - ethernet-phy-id001c.c899 + - ethernet-phy-id001c.c89a + then: + properties: + rx-polarity: false + rx-polarity-names: false + tx-polarity: false + tx-polarity-names: false examples: - |
@@ -96,3 +119,30 @@ examples: realtek,aldps-enable; }; }; + + - | + #include <dt-bindings/leds/common.h> + #include <dt-bindings/phy/phy.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@0 { + compatible = "ethernet-phy-id001c.c899"; + reg = <0>; + tx-polarity = <PHY_POL_INVERT>; + rx-polarity = <PHY_POL_INVERT>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@3 { + reg = <3>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_LAN; + }; + }; + }; + };
Signature · 1 line
2.55.0
PATCH 2/3 net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
In reply to Simon PolackBoards such as the Gemtek W1700K (Airoha AN7581) route the USXGMII lanes between the SoC and the PHY inverted and describe that in the device tree with the generic tx-polarity/rx-polarity properties. Nothing in the RTL8261C/D driver reads them and the Airoha PCS has no polarity handling of its own, so the inversion is never programmed. The copper side negotiates normally while the SerDes never trains and the netdev stays NO-CARRIER.
Lane polarity on this part lives behind the same VEND1 SerDes command window the RTL822x code already uses for in-band autoneg, in SerDes registers 0x0000 (bits 9:8) and 0x00c2 (bits 14:13). The register at VEND1 0xc1 that some other Realtek 10G PHYs use for the same purpose is not implemented on this die and reads back as zero after a write.
Add a read side and a read-modify-write helper to the command window, move rtl822x_serdes_write() up next to them so all three are visible from the RTL8261 code, apply the polarity from config_init() and select PHY_COMMON_PROPS for the property helpers. Only lanes actually described in the firmware node are touched; a board without the properties keeps whatever the boot loader and the PHY firmware left in place.
The bit assignment has been verified on an RTL8261CE (sub-model 0x00, PHY ID 0x001cc899): on the W1700K, SerDes register 0x0000 goes from 0x1403 to 0x1703 and 0x00c2 from 0x0000 to 0x6000, after which VEND1 0x758d reports the SerDes linked (0x0010 -> 0x001e) and the link comes up at 1G and 10G and passes traffic. The RTL8261C, RTL8261D and RTL8261D_VM share rtl8261x_config_init() and get the same treatment, but have not been tested with inverted lanes.
--- drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 174 +++++++++++++++++++++---- 2 files changed, 148 insertions(+), 27 deletions(-)
drivers/net/phy/realtek/Kconfig +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config REALTEK_PHY tristate "Realtek PHYs" + select PHY_COMMON_PROPS select PHY_PACKAGE help Currently supports RTL821x/RTL822x and fast ethernet PHYs
drivers/net/phy/realtek/realtek_main.c +147 -27
216 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 3/3 net: phy: realtek: add LED support for RTL8261C/D
In reply to Simon PolackFrom: Chad Monroe <[email protected]>
The RTL8261C/D use the same LED register block as the RTL8221B: one control register per LED at VEND2 0xd032 + 2 * index selecting the link speeds that light it, activity blink bits in LCR6 and per-LED polarity and enable bits in LCR7. Compared to the RTL8221B there are four LEDs instead of three, and two more speed bits for 5G and 10G.
Reuse the existing RTL822X_VND2_* definitions and add the two speed bits and the enable bit. The callbacks follow rtl822xb_led_*() closely, with two additions:
- led_polarity_set() honours active-low LEDs. The polarity bit in LCR7 doubles as the manual on/off level in led_brightness_set(), so the configured polarity is cached in the private data and restored by led_hw_control_set().
- led_hw_control_set() and led_brightness_set() set the output enable bit, which firmware normally leaves set already.
The callbacks duplicate most of rtl822xb_led_*(), differing only in the LED count, the speed mask and the LCR7 handling. Making the RTL8221B code table-driven and sharing it would be the right end state, but that touches a working driver and wants testing on an RTL8221B, so it is left for a follow-up series.
The callbacks are wired to the RTL8261C_CG and RTL8261CE_CG entries, which between them cover the parts this was tested on. RTL8261D_VM is left out for lack of hardware.
Tested on a Gemtek W1700K (Airoha AN7581) with an RTL8261CE: index 2 drives a yellow and index 3 a green LED on each 10G port. Under hardware control the link speed bits, the activity blink and the combined TRIGGER_NETDEV_LINK all take effect and offloading is confirmed through the netdev trigger. The polarity bit was verified to be active-high when clear on that board. Also tested on AN7581 and MT7988A boards with an RTL8261C and RTL8261D.
--- drivers/net/phy/realtek/realtek_main.c | 228 +++++++++++++++++++++++++ 1 file changed, 228 insertions(+)
drivers/net/phy/realtek/realtek_main.c +228 -0
@@ -183,12 +183,15 @@#define RTL822X_VND2_LCR_LINK_100 BIT(1)#define RTL822X_VND2_LCR_LINK_1000 BIT(2)#define RTL822X_VND2_LCR_LINK_2500 BIT(5) +#define RTL822X_VND2_LCR_LINK_5000 BIT(6) +#define RTL822X_VND2_LCR_LINK_10000 BIT(4)#define RTL822X_VND2_LCR6 0xd040#define RTL822X_VND2_LED_ACT (x) BIT(x)#define RTL822X_VND2_LCR7 0xd044#define RTL822X_VND2_LED_POLAR (x) BIT(x) +#define RTL822X_VND2_LED_EN (x) BIT((x) + 4)#define RTL8224_MII_RTCT 0x11#define RTL8224_MII_RTCT_ENABLE BIT(0)
@@ -305,6 +308,7 @@#define FW_SUB_MAGIC_8261D 0x32363144#define RTL8261X_POLL_TIMEOUT_MS 100#define RTL8261X_MAX_MMD_DEV 31 +#define RTL8261X_LED_COUNT 4#define RTL8261C_CE_FW_NAME "rtl_nic/rtl8261c.bin"#define RTL8261D_FW_NAME "rtl_nic/rtl8261d.bin"
@@ -364,6 +368,11 @@ struct rtl8261x_priv {const char *fw_name;u32 fw_sub_magic;bool fw_loaded; +/* LCR7's polarity bit doubles as the manual on/off level in +* led_brightness_set(), so the configured polarity is kept here +* to restore it whenever hardware control is set up again. +*/ +u8 led_active_low; };static int rtl821x_read_page (struct phy_device *phydev)
@@ -2530,6 +2539,215 @@ static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, RTL822X_VND2_LED_POLAR(index)); } +static int rtl8261x_led_hw_is_supported (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +const unsigned long act_mask =BIT (TRIGGER_NETDEV_RX ) | +BIT (TRIGGER_NETDEV_TX ); +const unsigned long link_mask =BIT (TRIGGER_NETDEV_LINK ) | +BIT (TRIGGER_NETDEV_LINK_10 ) | +BIT (TRIGGER_NETDEV_LINK_100 ) | +BIT (TRIGGER_NETDEV_LINK_1000 ) | +BIT (TRIGGER_NETDEV_LINK_2500 ) | +BIT (TRIGGER_NETDEV_LINK_5000 ) | +BIT (TRIGGER_NETDEV_LINK_10000 ); + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + +/* Filter out any other unsupported triggers. */ +if (rules & ~(link_mask | act_mask)) +return -EOPNOTSUPP ; + +/* RX and TX are not differentiated, they are not possible +* without combination with a link trigger. +*/ +if ((rules & act_mask) && !(rules & link_mask)) +return -EOPNOTSUPP ; + +return 0 ; +} + +static int rtl8261x_led_hw_control_get (struct phy_device *phydev,u8 index, +unsigned long *rules) +{ +const u16 all_links =RTL822X_VND2_LCR_LINK_10 | +RTL822X_VND2_LCR_LINK_100 | +RTL822X_VND2_LCR_LINK_1000 | +RTL822X_VND2_LCR_LINK_2500 | +RTL822X_VND2_LCR_LINK_5000 | +RTL822X_VND2_LCR_LINK_10000 ; +int val; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + + val =phy_read_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LED (index)); +if (val <0 ) +return val; + +if (val &RTL822X_VND2_LCR_LINK_10 ) +__set_bit (TRIGGER_NETDEV_LINK_10 , rules); + +if (val &RTL822X_VND2_LCR_LINK_100 ) +__set_bit (TRIGGER_NETDEV_LINK_100 , rules); + +if (val &RTL822X_VND2_LCR_LINK_1000 ) +__set_bit (TRIGGER_NETDEV_LINK_1000 , rules); + +if (val &RTL822X_VND2_LCR_LINK_2500 ) +__set_bit (TRIGGER_NETDEV_LINK_2500 , rules); + +if (val &RTL822X_VND2_LCR_LINK_5000 ) +__set_bit (TRIGGER_NETDEV_LINK_5000 , rules); + +if (val &RTL822X_VND2_LCR_LINK_10000 ) +__set_bit (TRIGGER_NETDEV_LINK_10000 , rules); + +if ((val & all_links) == all_links) +__set_bit (TRIGGER_NETDEV_LINK , rules); + + val =phy_read_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR6 ); +if (val <0 ) +return val; + +if (val &RTL822X_VND2_LED_ACT (index)) { +__set_bit (TRIGGER_NETDEV_RX , rules); +__set_bit (TRIGGER_NETDEV_TX , rules); + } + +return 0 ; +} + +static int rtl8261x_led_hw_control_set (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +struct rtl8261x_priv *priv = phydev->priv; +u16 lcr7 =RTL822X_VND2_LED_EN (index); +u16 val =0 ; +bool act; +int ret; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_10 , &rules)) + val |=RTL822X_VND2_LCR_LINK_10 ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_100 , &rules)) + val |=RTL822X_VND2_LCR_LINK_100 ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_1000 , &rules)) + val |=RTL822X_VND2_LCR_LINK_1000 ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_2500 , &rules)) + val |=RTL822X_VND2_LCR_LINK_2500 ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_5000 , &rules)) + val |=RTL822X_VND2_LCR_LINK_5000 ; + +if (test_bit (TRIGGER_NETDEV_LINK , &rules) || +test_bit (TRIGGER_NETDEV_LINK_10000 , &rules)) + val |=RTL822X_VND2_LCR_LINK_10000 ; + + ret =phy_write_mmd (phydev,MDIO_MMD_VEND2 , +RTL822X_VND2_LED (index), val); +if (ret <0 ) +return ret; + + act =test_bit (TRIGGER_NETDEV_RX , &rules) || +test_bit (TRIGGER_NETDEV_TX , &rules); + + ret =phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR6 , +RTL822X_VND2_LED_ACT (index), act ? +RTL822X_VND2_LED_ACT (index) :0 ); +if (ret <0 ) +return ret; + +/* Enable the output and restore the configured polarity, which +* led_brightness_set() may have used as a level. +*/ +if (priv->led_active_low &BIT (index)) + lcr7 |=RTL822X_VND2_LED_POLAR (index); + +return phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR7 , +RTL822X_VND2_LED_EN (index) | +RTL822X_VND2_LED_POLAR (index), lcr7); +} + +static int rtl8261x_led_brightness_set (struct phy_device *phydev,u8 index, +enum led_brightness value) +{ +struct rtl8261x_priv *priv = phydev->priv; +u16 lcr7 =RTL822X_VND2_LED_EN (index); +bool active_low, on; +int ret; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + +/* clear HW LED setup */ + ret =phy_write_mmd (phydev,MDIO_MMD_VEND2 , +RTL822X_VND2_LED (index),0 ); +if (ret <0 ) +return ret; + +/* clear HW LED blink */ + ret =phy_clear_bits_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR6 , +RTL822X_VND2_LED_ACT (index)); +if (ret <0 ) +return ret; + +/* With no link condition selected the output sits at its idle +* level, so inverting the polarity turns the LED on. +*/ + active_low = priv->led_active_low &BIT (index); + on = value !=LED_OFF ; +if (on != active_low) + lcr7 |=RTL822X_VND2_LED_POLAR (index); + +return phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR7 , +RTL822X_VND2_LED_EN (index) | +RTL822X_VND2_LED_POLAR (index), lcr7); +} + +static int rtl8261x_led_polarity_set (struct phy_device *phydev,int index, +unsigned long modes) +{ +struct rtl8261x_priv *priv = phydev->priv; +bool active_low = false; +u32 mode; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + +for_each_set_bit (mode, &modes, __PHY_LED_MODES_NUM) { +switch (mode) { +case PHY_LED_ACTIVE_LOW : + active_low = true; +break ; +case PHY_LED_ACTIVE_HIGH : +break ; +default : +return -EINVAL ; + } + } + +if (active_low) + priv->led_active_low |=BIT (index); +else + priv->led_active_low &= ~BIT (index); + +return phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR7 , +RTL822X_VND2_LED_POLAR (index), + active_low ?RTL822X_VND2_LED_POLAR (index) :0 ); +} +static int rtl822xb_led_hw_is_supported (struct phy_device *phydev,u8 index,unsigned long rules) {
@@ -3494,6 +3712,11 @@ static struct phy_driver realtek_drvs[] = { .soft_reset = genphy_c45_pma_soft_reset, .suspend = genphy_c45_pma_suspend, .resume = genphy_c45_pma_resume, + .led_brightness_set = rtl8261x_led_brightness_set, + .led_hw_is_supported = rtl8261x_led_hw_is_supported, + .led_hw_control_get = rtl8261x_led_hw_control_get, + .led_hw_control_set = rtl8261x_led_hw_control_set, + .led_polarity_set = rtl8261x_led_polarity_set, }, {PHY_ID_MATCH_EXACT (RTL_8261CE_CG ), .name = "Realtek RTL8261CE 10Gbps PHY",
@@ -3507,6 +3730,11 @@ static struct phy_driver realtek_drvs[] = { .soft_reset = genphy_c45_pma_soft_reset, .suspend = genphy_c45_pma_suspend, .resume = genphy_c45_pma_resume, + .led_brightness_set = rtl8261x_led_brightness_set, + .led_hw_is_supported = rtl8261x_led_hw_is_supported, + .led_hw_control_get = rtl8261x_led_hw_control_get, + .led_hw_control_set = rtl8261x_led_hw_control_set, + .led_polarity_set = rtl8261x_led_polarity_set, }, {PHY_ID_MATCH_EXACT (RTL_8261D_VM ), .name = "Realtek RTL8261D_VM 10Gbps PHY",
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 1/3] dt-bindings: net: realtek,rtl82xx: Document RTL8261C/D PHYs
In reply to Simon PolackThank 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] Concern (validated as FALSE POSITIVE / resolved inside the series): the binding enables rx-polarity/tx-polarity(-names) for…
- [Low] The new unconditional - $ref: /schemas/phy/phy-common- props.yaml# in…
- [Low] Concern (validated as FALSE POSITIVE / resolved inside the series): the binding permits a leds node for ethernet-phy-…
- [Low] The commit message states the leds node is allowed for the new parts "the way it is already allowed for the RTL8221B", but the only…
- [Low] Concern (validated as FALSE POSITIVE): the binding references phy-common-props.yaml wholesale for the RTL8261C/D compatibles without…
--
dt-bindings: net: realtek,rtl82xx: Document RTL8261C/D PHYs
Adds the three compatible strings for the RTL8261C/D family, allows a leds node for them, and references phy-common-props.yaml so the tx-polarity and rx-polarity properties can be used on those parts. A second example using inverted SerDes polarity and one LED is added.
Two questions below, one about the changelog and one about the schema.
Quoted 2 lines
These parts drive four LEDs from the VEND2 LED register block, so allow the leds node for them the way it is already allowed for the RTL8221B.
[Severity: Low]
Is the reference to the RTL8221B here correct? The only compatible that was exempted from "leds: false" before this patch is ethernet-phy-id001c.c916, and in drivers/net/phy/realtek/realtek_main.c the PHY_ID_MATCH_EXACT(0x001cc916) entry carries:
.name = "RTL8211F Gigabit Ethernet",
The RTL8221B ids are RTL_8221B_VB_CG (0x001cc849) and RTL_8221B_VM_CG (0x001cc84a), i.e. compatibles ethernet-phy-id001c.c849 and ethernet-phy-id001c.c84a, and those are still forced to "leds: false" by this binding both before and after the patch.
Should the message name the RTL8211F instead?
Quoted 4 lines
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +0
-0
[ ... ]
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml unevaluatedProperties: false · line 80
Quoted 5 lines
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +1
-0@@ -74,15 +77,35 @@ unevaluatedProperties: false allOf: - $ref: ethernet-phy.yaml# + - $ref: /schemas/phy/phy-common-props.yaml#
[Severity: Low]
This $ref is unconditional, so all six properties defined in phy-common-props.yaml become evaluated for every compatible in this binding, not just the three new ones. Besides the four polarity properties, phy-common-props.yaml also defines:
tx-p2p-microvolt:
description:
Transmit amplitude voltages in microvolts, peak-to-peak. ...
tx-p2p-microvolt-names:
Since the restriction block below only sets the polarity properties to false, does this now let tx-p2p-microvolt and tx-p2p-microvolt-names pass dt_binding_check on every Realtek PHY compatible listed in this file (ethernet-phy-id001c.c916, c849, c84a and the rest), where before the patch "unevaluatedProperties: false" rejected them? There is no reader for a transmit amplitude property anywhere in drivers/net/phy/realtek/, so a device tree setting it would be silently accepted and ignored.
Would adding
tx-p2p-microvolt: false
tx-p2p-microvolt-names: false
alongside the polarity entries, or moving the $ref under an RTL8261-only branch, be preferable?
Quoted 29 lines
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +20
-1- if: not: properties: compatible: contains: - const: ethernet-phy-id001c.c916 + enum: + - ethernet-phy-id001c.c898 + - ethernet-phy-id001c.c899 + - ethernet-phy-id001c.c89a + - ethernet-phy-id001c.c916 then: properties: leds: false + - if: + not: + properties: + compatible: + contains: + enum: + - ethernet-phy-id001c.c898 + - ethernet-phy-id001c.c899 + - ethernet-phy-id001c.c89a + then: + properties: + rx-polarity: false + rx-polarity-names: false + tx-polarity: false + tx-polarity-names: false
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921161817.565185-1-spolack%2Bgit%40mailbox.org
[email protected]
AI reviewRe: [PATCH net-next 3/3] net: phy: realtek: add LED support for RTL8261C/D
In reply to Simon PolackThank 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] Asymmetric LED register programming:
rtl8261x_led_hw_control_set() (drivers/net/phy/realtek/realtek_main.c,…
- [Low] rtl8261x_led_hw_control_get() (drivers/net/phy/realtek/realtek_main.c ~2570-2620) reports the…
- [Low] rtl8261x_led_hw_is_supported() (drivers/net/phy/realtek/realtek_main.c ~2542-2568) accepts asymmetric…
- [Low] Out-of-range shift evaluated before the bounds check: in both rtl8261x_led_hw_control_set() and rtl8261x_led_brightness_set() the…
Pre-existing issues:
- [Low] Claimed non-atomic hardware programming sequence:
rtl8261x_led_hw_control_set() and rtl8261x_led_brightness_set() each…
--
net: phy: realtek: add LED support for RTL8261C/D
Adds LED callbacks for the RTL8261C/D reusing the RTL8221B LED register block, with four LEDs, extra 5G/10G link speed bits, a new per-LED output enable bit and caching of the configured polarity in the private data. The callbacks are wired into the RTL8261C_CG and RTL8261CE_CG driver entries.
A few questions below.
Quoted 17 lines
drivers/net/phy/realtek/realtek_main.c +3
-0@@ -183,12 +183,15 @@#define RTL822X_VND2_LCR_LINK_100 BIT(1)#define RTL822X_VND2_LCR_LINK_1000 BIT(2)#define RTL822X_VND2_LCR_LINK_2500 BIT(5) +#define RTL822X_VND2_LCR_LINK_5000 BIT(6) +#define RTL822X_VND2_LCR_LINK_10000 BIT(4)#define RTL822X_VND2_LCR6 0xd040#define RTL822X_VND2_LED_ACT (x) BIT(x)#define RTL822X_VND2_LCR7 0xd044#define RTL822X_VND2_LED_POLAR (x) BIT(x) +#define RTL822X_VND2_LED_EN (x) BIT((x) + 4)
[ ... ]
Quoted 5 lines
drivers/net/phy/realtek/realtek_main.c +1
-0@@ -305,6 +308,7 @@#define FW_SUB_MAGIC_8261D 0x32363144#define RTL8261X_POLL_TIMEOUT_MS 100#define RTL8261X_MAX_MMD_DEV 31 +#define RTL8261X_LED_COUNT 4
[ ... ]
Quoted 6 lines
drivers/net/phy/realtek/realtek_main.c +5
-0@@ -2530,6 +2539,215 @@ static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, +static int rtl8261x_led_hw_is_supported (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +const unsigned long act_mask =BIT (TRIGGER_NETDEV_RX ) | +BIT (TRIGGER_NETDEV_TX );
[ ... ]
drivers/net/phy/realtek/realtek_main.c static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, · line 2569
Quoted 8 lines
drivers/net/phy/realtek/realtek_main.c +8
-0+/* RX and TX are not differentiated, they are not possible +* without combination with a link trigger. +*/ +if ((rules & act_mask) && !(rules & link_mask)) +return -EOPNOTSUPP ; + +return 0 ; +}
[Severity: Low]
Should rtl8261x_led_hw_is_supported() also reject asymmetric activity requests? As written, LINK|RX without TX (and LINK|TX without RX) passes validation, but the hardware bit those map to is a single combined RX/TX activity bit:
rtl8261x_led_hw_control_set()
act = test_bit(TRIGGER_NETDEV_RX, &rules) || test_bit(TRIGGER_NETDEV_TX, &rules);
rtl8261x_led_hw_control_get()
if (val & RTL822X_VND2_LED_ACT(index)) {
__set_bit(TRIGGER_NETDEV_RX, rules);
__set_bit(TRIGGER_NETDEV_TX, rules);
}Since hw_is_supported() returns 0, the netdev trigger offloads the request instead of falling back to software blinking, so an rx=1 tx=0 configuration blinks on transmit as well, which differs from what Documentation/ABI/testing/sysfs-class-led-trigger-netdev describes for writing 0 to tx.
rtl8211f_led_hw_is_supported() in the same file handles the same hardware limitation by rejecting the mismatch:
/* RX and TX are not differentiated, either both are set or not set. */ if (!(rules & BIT(TRIGGER_NETDEV_RX)) ^ !(rules & BIT(TRIGGER_NETDEV_TX))) return -EOPNOTSUPP;
Would following that variant instead of the rtl822xb one be preferable here?
Quoted 21 lines
drivers/net/phy/realtek/realtek_main.c +21
-0+ +static int rtl8261x_led_hw_control_get (struct phy_device *phydev,u8 index, +unsigned long *rules) +{ +const u16 all_links =RTL822X_VND2_LCR_LINK_10 | +RTL822X_VND2_LCR_LINK_100 | +RTL822X_VND2_LCR_LINK_1000 | +RTL822X_VND2_LCR_LINK_2500 | +RTL822X_VND2_LCR_LINK_5000 | +RTL822X_VND2_LCR_LINK_10000 ; +int val; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ; + + val =phy_read_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LED (index)); +if (val <0 ) +return val; + +if (val &RTL822X_VND2_LCR_LINK_10 ) +__set_bit (TRIGGER_NETDEV_LINK_10 , rules);
[ ... ]
drivers/net/phy/realtek/realtek_main.c static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, · line 2608
Quoted 5 lines
drivers/net/phy/realtek/realtek_main.c +5
-0+if (val &RTL822X_VND2_LCR_LINK_10000 ) +__set_bit (TRIGGER_NETDEV_LINK_10000 , rules); + +if ((val & all_links) == all_links) +__set_bit (TRIGGER_NETDEV_LINK , rules);
[Severity: Low]
Can this report a rule combination that the netdev trigger itself refuses? When all six speed bits are set, the per-speed bits stay set and TRIGGER_NETDEV_LINK is added on top.
netdev_trig_activate() in drivers/leds/trigger/ledtrig-netdev.c takes the bitmap verbatim:
rc = led_cdev->hw_control_get(led_cdev, &mode); if (!rc) trigger_data->mode = mode;
and netdev_led_attr_store() rejects that same combination:
if (test_bit(TRIGGER_NETDEV_LINK, &mode) && (test_bit(TRIGGER_NETDEV_LINK_10, &mode) || ... )) return -EINVAL;
So with an all-speeds hardware configuration, would every subsequent write to link_10 ... rx/tx/full_duplex fail with -EINVAL until the user clears link? Should the getter clear the per-speed bits when it sets TRIGGER_NETDEV_LINK?
The same pattern already exists in rtl822xb_led_hw_control_get() and rtl8211e_led_hw_control_get(), so any canonicalisation probably belongs there too, but this patch adds a new instance.
drivers/net/phy/realtek/realtek_main.c static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, · line 2620
Quoted 12 lines
drivers/net/phy/realtek/realtek_main.c +12
-0+ + val =phy_read_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR6 ); +if (val <0 ) +return val; + +if (val &RTL822X_VND2_LED_ACT (index)) { +__set_bit (TRIGGER_NETDEV_RX , rules); +__set_bit (TRIGGER_NETDEV_TX , rules); + } + +return 0 ; +}
[Severity: Low]
Should rtl8261x_led_hw_control_get() also look at LCR7? It reads only RTL822X_VND2_LED(index) and the LCR6 activity bit, while rtl8261x_led_hw_control_set() is the only place that programs RTL822X_VND2_LED_EN(index), so the get path cannot tell whether the output driver is actually enabled.
The commit message says the enable bit is one "which firmware normally leaves set already". If a board boots with link condition bits set but the enable bit clear, netdev_trig_activate() imports those rules and also does:
trigger_data->hw_control = true; ... rc = led_cdev->hw_control_get(led_cdev, &mode); if (!rc) trigger_data->mode = mode;
without calling hw_control_set(), so nothing re-asserts the enable bit. Would the LED then stay dark while userspace is told the triggers are offloaded, with software blinking suppressed as well? Should a clear enable bit be reported as not offloaded?
drivers/net/phy/realtek/realtek_main.c static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, · line 2632
Quoted 12 lines
drivers/net/phy/realtek/realtek_main.c +12
-0+ +static int rtl8261x_led_hw_control_set (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +struct rtl8261x_priv *priv = phydev->priv; +u16 lcr7 =RTL822X_VND2_LED_EN (index); +u16 val =0 ; +bool act; +int ret; + +if (index >=RTL8261X_LED_COUNT ) +return -EINVAL ;
[Severity: Low]
Is the shift in the initialiser evaluated before index is validated? RTL822X_VND2_LED_EN(index) expands to UL(1) << (index + 4), and it runs ahead of the index >= RTL8261X_LED_COUNT test. The same ordering appears in rtl8261x_led_brightness_set().
index comes from the DT LED node reg property, and of_phy_led() in drivers/net/phy/phy_device.c only bounds it at U8_MAX:
err = of_property_read_u32(led, "reg", &index); if (err) return err; if (index > U8_MAX) return -EINVAL;
So a device tree with led@3c or higher registers a LED classdev whose brightness write reaches this initialiser with a shift count of 64 or more on an unsigned long, which is undefined behaviour and should produce a UBSAN shift-out-of-bounds report. Can the initialisation be moved below the bounds check? The existing rtl822xb_* and rtl8211e_* callbacks compute their masks only after validating index.
[ ... ]
Quoted 14 lines
drivers/net/phy/realtek/realtek_main.c +14
-0+ ret =phy_write_mmd (phydev,MDIO_MMD_VEND2 , +RTL822X_VND2_LED (index), val); +if (ret <0 ) +return ret; + + act =test_bit (TRIGGER_NETDEV_RX , &rules) || +test_bit (TRIGGER_NETDEV_TX , &rules); + + ret =phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR6 , +RTL822X_VND2_LED_ACT (index), act ? +RTL822X_VND2_LED_ACT (index) :0 ); +if (ret <0 ) +return ret; +
drivers/net/phy/realtek/realtek_main.c static int rtl822xb_led_brightness_set(struct phy_device *phydev, u8 index, · line 2681
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+/* Enable the output and restore the configured polarity, which +* led_brightness_set() may have used as a level. +*/ +if (priv->led_active_low &BIT (index)) + lcr7 |=RTL822X_VND2_LED_POLAR (index); + +return phy_modify_mmd (phydev,MDIO_MMD_VEND2 ,RTL822X_VND2_LCR7 , +RTL822X_VND2_LED_EN (index) | +RTL822X_VND2_LED_POLAR (index), lcr7); +}
[Severity: Low]
This isn't a bug introduced by this patch, but the three MDIO transactions here (per-LED link conditions, LCR6 activity, LCR7 enable/polarity) return on the first failure without undoing the earlier writes, so a mid-sequence failure leaves the LED enabled with new link conditions, stale activity state and the manual-mode polarity level. On the success path the LED is also briefly inverted between the first and the last write because LCR7's polarity bit doubles as the manual level.
rtl822xb_led_hw_control_set() and rtl822xb_led_brightness_set() already use the same unwound sequence on the same register block, so this is the existing convention in the driver rather than something new, and the same applies to rtl8261x_led_brightness_set() here. Worth noting only in case a rollback or a quiesce-first ordering is wanted for the new callbacks.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921161817.565185-1-spolack%2Bgit%40mailbox.org
[email protected]
AI reviewRe: [PATCH net-next 2/3] net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
In reply to Simon PolackThank 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] Binding/driver contract mismatch for the generic tx- polarity/rx-polarity ABI: the new binding (patch "dt-bindings: net:…
- [Low] Reported concern: the patch fixes a user-visible NO-CARRIER condition but carries no Fixes: tag (suggested Fixes: b772b5ae4537…
- [Low] Reported concern: rtl8261x_config_serdes_polarity() commits RTL8261X_SERDES_POL_REG0 before attempting RTL8261X_SERDES_POL_REGC2…
--
net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
This adds a read and a read-modify-write helper to the RTL822x VEND1 SerDes command window, moves rtl822x_serdes_write() next to them, and programs the host-side SerDes lane polarity described by the generic tx-polarity and rx-polarity firmware properties from rtl8261x_config_init(). REALTEK_PHY now selects PHY_COMMON_PROPS for the property helpers.
A couple of questions below.
Quoted 2 lines
The copper side negotiates normally while the SerDes never trains and the netdev stays NO-CARRIER.
[Severity: Low]
Since this fixes a user-visible NO-CARRIER condition, should the patch carry a Fixes: tag, e.g.
For completeness: at the baseline revision Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml lists no ethernet-phy-id001c.c898/c899/c89a compatible and has no $ref to /schemas/phy/phy-common-props.yaml, so tx-polarity/rx-polarity only become part of the ABI for these PHYs through the sibling binding patch in this series. On that reading no released kernel can regress, and a Fixes: tag may not be appropriate after all - worth confirming which way this should go.
Quoted 4 lines
drivers/net/phy/realtek/realtek_main.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/phy/realtek/realtek_main.c +1
-0@@ -708,18 +723,147 @@ static int rtl8261x_config_aneg(struct phy_device *phydev)return 0 ; } +static int rtl822x_serdes_wait (struct phy_device *phydev)
[ ... ]
Quoted 21 lines
drivers/net/phy/realtek/realtek_main.c +21
-0+/* The host-side SerDes lanes are only inverted when the board says so. +* Lanes the firmware node does not describe are left as the boot loader +* and PHY firmware left them. +*/ +static int rtl8261x_config_serdes_polarity (struct phy_device *phydev) +{ +bool tx_present, rx_present, tx_invert = false, rx_invert = false; +u16 reg0_mask =0 , reg0_set =0 , regc2_mask =0 , regc2_set =0 ; +struct fwnode_handle *fwnode =dev_fwnode (&phydev->mdio.dev); +const char *mode =phy_modes (phydev->interface); +unsigned int pol; +int ret; + + tx_present =fwnode_property_present (fwnode,"tx-polarity" ); + rx_present =fwnode_property_present (fwnode,"rx-polarity" ); +if (!tx_present && !rx_present) +return 0 ; + +if (tx_present) { + ret =phy_get_manual_tx_polarity (fwnode, mode, &pol); +if (ret)
drivers/net/phy/realtek/realtek_main.c static int rtl8261x_config_aneg(struct phy_device *phydev) · line 822
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+return ret; + tx_invert = pol ==PHY_POL_INVERT ; + } + +if (rx_present) { + ret =phy_get_manual_rx_polarity (fwnode, mode, &pol); +if (ret) +return ret; + rx_invert = pol ==PHY_POL_INVERT ; + }
[Severity: Medium]
Is the range of values this accepts narrower than what the binding allows?
phy-common-props.yaml constrains rx-polarity items to enum [0, 1, 2], and the realtek,rtl82xx.yaml conditional in this series only disables the property for compatibles other than ethernet-phy-id001c.c898/c899/c89a, so <PHY_POL_AUTO> validates on these nodes. The helper used here only permits BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT):
int __must_check phy_get_manual_rx_polarity(struct fwnode_handle *fwnode,
const char *mode_name,
unsigned int *val)
{
return phy_get_rx_polarity(fwnode, mode_name,
BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
PHY_POL_NORMAL, val);
}so the lookup returns -EOPNOTSUPP for PHY_POL_AUTO. Should the binding narrow the enum to [0, 1] for these compatibles, or should this code treat PHY_POL_AUTO as "leave the lane alone"?
A second shape has the same effect. When tx-polarity/rx-polarity is a per-mode list and the *-polarity-names list does not contain the active interface name and has no "default" entry, fwnode_get_u32_prop_for_name() fails:
drivers/phy/phy-common-props.c:fwnode_get_u32_prop_for_name() {
...
if (idx < 0 && n_props != 1) {
pr_err(...);
return -EINVAL;
} if (n_props == 1) {
err = fwnode_property_read_u32(fwnode, props_title, val);
...}
The $defs/protocol-names text in the binding says the system should use the manufacturer default value when no name matches, which does not look like what happens here. And in the n_props == 1 case the single value is applied even though the name did not match, so a polarity described for one protocol gets programmed while running another - is that intended?
Note the lookup key is computed at config_init() time:
const char *mode = phy_modes(phydev->interface);
and phy_modes() returns "" for PHY_INTERFACE_MODE_NA, a string that can never appear in the binding's protocol-names enum, so the unmatched-name paths are reachable when the interface is still unresolved at attach time (phylink_fwnode_phy_connect() passes pl->link_interface, which may still be PHY_INTERFACE_MODE_NA).
Quoted 17 lines
drivers/net/phy/realtek/realtek_main.c +17
-0+ +if (tx_present) { + reg0_mask |=RTL8261X_SERDES_POL_REG0_TX ; + regc2_mask |=RTL8261X_SERDES_POL_REGC2_TX ; +if (tx_invert) { + reg0_set |=RTL8261X_SERDES_POL_REG0_TX ; + regc2_set |=RTL8261X_SERDES_POL_REGC2_TX ; + } + } + +if (rx_present) { + reg0_mask |=RTL8261X_SERDES_POL_REG0_RX ; + regc2_mask |=RTL8261X_SERDES_POL_REGC2_RX ; +if (rx_invert) { + reg0_set |=RTL8261X_SERDES_POL_REG0_RX ; + regc2_set |=RTL8261X_SERDES_POL_REGC2_RX ; + }
drivers/net/phy/realtek/realtek_main.c static int rtl8261x_config_aneg(struct phy_device *phydev) · line 849
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+ } + + ret =rtl822x_serdes_modify (phydev,RTL8261X_SERDES_POL_REG0 , + reg0_mask, reg0_set); +if (ret <0 ) +return ret; + +return rtl822x_serdes_modify (phydev,RTL8261X_SERDES_POL_REGC2 , + regc2_mask, regc2_set); +}
[Severity: Low]
This isn't a bug, but the RTL8261X_SERDES_POL_REG0 update is committed before RTL8261X_SERDES_POL_REGC2 is attempted, with no rollback, so an MDIO failure on the second rtl822x_serdes_modify() leaves the two registers describing different polarities.
Working against that being a problem: the error is propagated out of rtl8261x_config_init(), phy_init_hw() aborts on it, and phy_attach_direct() takes its error path and calls phy_detach_internal(), so the half-programmed PHY is never used for a link, and the sequence is idempotent on the next phy_init_hw(). Mentioning it only in case a comment here is worth having.
Quoted 10 lines
static int
rtl8261x_config_init(struct phy_device *phydev){drivers/net/phy/realtek/realtek_main.c +1
-1struct rtl8261x_priv *priv = phydev->priv; +int ret;/* The firmware parameters are preserved across IEEE soft resets and * suspend/resume cycles. Reloading is only necessary after a power * cycle or hard reset. */ -if (priv->fw_name && !priv->fw_loaded)
drivers/net/phy/realtek/realtek_main.c static int rtl8261x_config_aneg(struct phy_device *phydev) · line 867
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +6
-2-return rtl8261x_fw_load (phydev); +if (priv->fw_name && !priv->fw_loaded) { + ret =rtl8261x_fw_load (phydev); +if (ret) +return ret; + } -return 0 ; +return rtl8261x_config_serdes_polarity (phydev); }
Returning the polarity parse error from config_init() makes any of the firmware descriptions above fatal to PHY initialisation:
drivers/net/phy/phy_device.c:phy_init_hw() {
...
if (phydev->drv->config_init) {
ret = phydev->drv->config_init(phydev);
if (ret < 0)
return ret;
...
}and phy_attach_direct() then goes to its error label and detaches the PHY, so the netdev never comes up at all. Would it be better to warn and keep the lane untouched when the properties cannot be interpreted?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921161817.565185-1-spolack%2Bgit%40mailbox.org
RE: [PATCH net-next 2/3] net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
In reply to Simon PolackQuoted 82 lines
Boards such as the Gemtek W1700K (Airoha AN7581) route the USXGMII lanes between the SoC and the PHY inverted and describe that in the device tree with the generic tx-polarity/rx-polarity properties.
Nothing in the RTL8261C/D driver reads them and the Airoha PCS has no polarity handling of its own, so the inversion is never programmed. The copper side negotiates normally while the SerDes never trains and the netdev stays NO-CARRIER.Lane polarity on this part lives behind the same VEND1 SerDes command window the RTL822x code already uses for in-band autoneg, in SerDes registers
0x0000(bits 9:8) and0x00c2(bits 14:13). The register at
VEND10xc1that some other Realtek 10G PHYs use for the same purpose is not implemented on this die and reads back as zero after a write.Add a read side and a read-modify-write helper to the command window, move
rtl822x_serdes_write()up next to them so all three are visible from the RTL8261 code, apply the polarity fromconfig_init()and selectPHY_COMMON_PROPSfor the property helpers. Only lanes actually described in the firmware node are touched; a board without the properties keeps whatever the boot loader and the PHY firmware left in place.The bit assignment has been verified on an RTL8261CE (sub-model
0x00, PHY ID0x001cc899): on the W1700K, SerDes register0x0000goes from0x1403to0x1703and0x00c2from0x0000to0x6000, after which VEND10x758dreports the SerDes linked (0x0010->0x001e) and the link comes up at 1G and 10G and passes traffic. The RTL8261C, RTL8261D andRTL8261D_VMsharertl8261x_config_init()and get the same treatment, but have not been tested with inverted lanes.Assisted-by LLMSigned-off-by Simon Polack <[email protected]>---
drivers/net/phy/realtek/Kconfig| 1 +drivers/net/phy/realtek/realtek_main.c| 174 +++++++++++++++++++++----2 files changed, 148 insertions(+), 27 deletions(-)drivers/net/phy/realtek/Kconfig +1
-0@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config REALTEK_PHY tristate "Realtek PHYs" + select PHY_COMMON_PROPS select PHY_PACKAGE help Currently supports RTL821x/RTL822x and fast ethernet PHYs diff --git
a/drivers/net/phy/realtek/realtek_main.cb/drivers/net/phy/realtek/realtek_main.c
index1e670638dd1c..04d397f0a2d8100644drivers/net/phy/realtek/realtek_main.c +3
-0@@ -13,9 +13,11 @@#include <linux/firmware.h> #include <linux/of.h> #include <linux/phy.h> +#include <linux/phy/phy-common-props.h> #include <linux/pm_wakeirq.h> #include <linux/netdevice.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/delay.h> #include <linux/clk.h> #include <linux/string_choices.h> @@ -164,6 +166,7 @@#define RTL822X_VND1_SERDES_INBAND_DISABLE 0x71d0#define RTL822X_VND1_SERDES_INBAND_ENABLE 0x70d0#define RTL822X_VND1_SERDES_DATA 0x7589 +#define RTL822X_VND1_SERDES_RDATA 0x758a#define RTL822X_VND2_TO_PAGE (reg) ((reg) >> 4)#define RTL822X_VND2_TO_PAGE_REG (reg) (16 + (((reg) & GENMASK(3,0)) >> 1))
drivers/net/phy/realtek/realtek_main.c +4
-0@@ -271,6 +274,18 @@#define RTL8261X_INT_ALDPS_CHG BIT(9)#define RTL8261X_INT_JABBER BIT(10) +/* SerDes lane polarity, behind the VEND1 SerDes command window. This +is not +* the global inversion bit that other Realtek 10G PHYs use; the bit +* assignment below has only been verified on an RTL8261CE reporting
drivers/net/phy/realtek/realtek_main.c line 290
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+PHY ID +* 0x001cc899. +*/ +#define RTL8261X_SERDES_POL_REG0 0x0000 +#define RTL8261X_SERDES_POL_REG0_TX BIT(8) +#define RTL8261X_SERDES_POL_REG0_RX BIT(9) +#define RTL8261X_SERDES_POL_REGC2 0x00c2 +#define RTL8261X_SERDES_POL_REGC2_TX BIT(14) #define +RTL8261X_SERDES_POL_REGC2_RX BIT(13) +
Hi,
Thanks for submitting this patch.
The serdes registers modified in this patch are not unified across RTL8261 family. This patch will lead to undefined behaviors on other IC. And operating these SerDes registers requires a specific hardware control flow. The direct manipulation used in this patch will introduce unknown risk.
Therefore, we kindly suggest drop this patch.
BRS,
Javen
RE: [PATCH net-next 3/3] net: phy: realtek: add LED support for RTL8261C/D
In reply to Simon PolackQuoted 67 lines
The RTL8261C/D use the same LED register block as the RTL8221B: one control register per LED at VEND2
0xd032+ 2 * index selecting the link speeds that light it, activity blink bits in LCR6 and per-LED polarity and enable bits in LCR7. Compared to the RTL8221B there are four LEDs instead of three, and two more speed bits for 5G and 10G.Reuse the existing RTL822X_VND2_* definitions and add the two speed bits and the enable bit. The callbacks follow rtl822xb_led_*() closely, with two additions:
-
led_polarity_set()honours active-low LEDs. The polarity bit in LCR7 doubles as the manual on/off level inled_brightness_set(), so the configured polarity is cached in the private data and restored byled_hw_control_set().-
led_hw_control_set()andled_brightness_set()set the output enable bit, which firmware normally leaves set already.The callbacks duplicate most of rtl822xb_led_*(), differing only in the LED count, the speed mask and the LCR7 handling. Making the RTL8221B code table-driven and sharing it would be the right end state, but that touches a working driver and wants testing on an RTL8221B, so it is left for a follow-up series.
The callbacks are wired to the
RTL8261C_CGandRTL8261CE_CGentries, which between them cover the parts this was tested on.RTL8261D_VMis left out for lack of hardware.Tested on a Gemtek W1700K (Airoha AN7581) with an RTL8261CE: index 2 drives a yellow and index 3 a green LED on each 10G port. Under hardware control the link speed bits, the activity blink and the combined
TRIGGER_NETDEV_LINKall take effect and offloading is confirmed through the netdev trigger. The polarity bit was verified to be active-high when clear on that board. Also tested on AN7581 and MT7988A boards with an RTL8261C and RTL8261D.Signed-off-by Chad Monroe <[email protected]>Co-developed-by Simon Polack <[email protected]>Signed-off-by Simon Polack <[email protected]>Assisted-by LLM---
drivers/net/phy/realtek/realtek_main.c| 228
+++++++++++++++++++++++++1 file changed, 228 insertions(+)drivers/net/phy/realtek/realtek_main.c +3
-0@@ -183,12 +183,15 @@#define RTL822X_VND2_LCR_LINK_100 BIT(1)#define RTL822X_VND2_LCR_LINK_1000 BIT(2)#define RTL822X_VND2_LCR_LINK_2500 BIT(5) +#define RTL822X_VND2_LCR_LINK_5000 BIT(6) +#define RTL822X_VND2_LCR_LINK_10000 BIT(4)#define RTL822X_VND2_LCR6 0xd040#define RTL822X_VND2_LED_ACT (x) BIT(x)#define RTL822X_VND2_LCR7 0xd044#define RTL822X_VND2_LED_POLAR (x) BIT(x) +#define RTL822X_VND2_LED_EN (x) BIT((x) + 4)#define RTL8224_MII_RTCT 0x11#define RTL8224_MII_RTCT_ENABLE BIT(0)
drivers/net/phy/realtek/realtek_main.c line 311
Quoted 4 lines
drivers/net/phy/realtek/realtek_main.c +1
-0@@ -305,6 +308,7 @@#define FW_SUB_MAGIC_8261D 0x32363144#define RTL8261X_POLL_TIMEOUT_MS 100#define RTL8261X_MAX_MMD_DEV 31 +#define RTL8261X_LED_COUNT 4
Hi,
We kindly suggest dropping this patch for the same reason as in Patch 2/3.
LED config is related to HW config and will be configured via firmware.
BRs,
Javen
RE: [PATCH net-next 2/3] net: phy: realtek: apply SerDes lane polarity on RTL8261C/D
In reply to JavenResending text-encoded:
Hi Javen,
Thanks for reviewing.
On scope: this patch only affects the parts the driver binds, PHY IDs 0x001cc898, 0x001cc899 and 0x001cc89a. The RTL8261N (0x001ccaf3) isn't supported upstream and isn't touched.
Understood on the revision dependence. The problem remains that the W1700K routes the lanes inverted, and without programming the polarity its 10G ports never link. How should such a board be supported?
If there is a supported way to set lane polarity - a register the driver writes and the PHY firmware acts on, so the control flow stays with the hardware - I'd gladly use that instead of the direct SerDes access. Otherwise the alternative I see is restricting the patch to the verified variant (0x001cc899, sub-model 0x00) and leaving every other part untouched.
Simon
Am 28. September 2026 09:17:00 MESZ schrieb Javen <[email protected]>:
Quoted 104 lines
Quoted 82 lines
Boards such as the Gemtek W1700K (Airoha AN7581) route the USXGMII lanes between the SoC and the PHY inverted and describe that in the device tree with the generic tx-polarity/rx-polarity properties.
Nothing in the RTL8261C/D driver reads them and the Airoha PCS has no polarity handling of its own, so the inversion is never programmed. The copper side negotiates normally while the SerDes never trains and the netdev stays NO-CARRIER.Lane polarity on this part lives behind the same VEND1 SerDes command window the RTL822x code already uses for in-band autoneg, in SerDes registers
0x0000(bits 9:8) and0x00c2(bits 14:13). The register at
VEND10xc1that some other Realtek 10G PHYs use for the same purpose is not implemented on this die and reads back as zero after a write.Add a read side and a read-modify-write helper to the command window, move
rtl822x_serdes_write()up next to them so all three are visible from the RTL8261 code, apply the polarity fromconfig_init()and selectPHY_COMMON_PROPSfor the property helpers. Only lanes actually described in the firmware node are touched; a board without the properties keeps whatever the boot loader and the PHY firmware left in place.The bit assignment has been verified on an RTL8261CE (sub-model
0x00, PHY ID0x001cc899): on the W1700K, SerDes register0x0000goes from0x1403to0x1703and0x00c2from0x0000to0x6000, after which VEND10x758dreports the SerDes linked (0x0010->0x001e) and the link comes up at 1G and 10G and passes traffic. The RTL8261C, RTL8261D andRTL8261D_VMsharertl8261x_config_init()and get the same treatment, but have not been tested with inverted lanes.Assisted-by LLMSigned-off-by Simon Polack <[email protected]>---
drivers/net/phy/realtek/Kconfig| 1 +drivers/net/phy/realtek/realtek_main.c| 174 +++++++++++++++++++++----2 files changed, 148 insertions(+), 27 deletions(-)drivers/net/phy/realtek/Kconfig +1
-0@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config REALTEK_PHY tristate "Realtek PHYs" + select PHY_COMMON_PROPS select PHY_PACKAGE help Currently supports RTL821x/RTL822x and fast ethernet PHYs diff --git
a/drivers/net/phy/realtek/realtek_main.cb/drivers/net/phy/realtek/realtek_main.c
index1e670638dd1c..04d397f0a2d8100644drivers/net/phy/realtek/realtek_main.c +3
-0@@ -13,9 +13,11 @@#include <linux/firmware.h> #include <linux/of.h> #include <linux/phy.h> +#include <linux/phy/phy-common-props.h> #include <linux/pm_wakeirq.h> #include <linux/netdevice.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/delay.h> #include <linux/clk.h> #include <linux/string_choices.h> @@ -164,6 +166,7 @@#define RTL822X_VND1_SERDES_INBAND_DISABLE 0x71d0#define RTL822X_VND1_SERDES_INBAND_ENABLE 0x70d0#define RTL822X_VND1_SERDES_DATA 0x7589 +#define RTL822X_VND1_SERDES_RDATA 0x758a#define RTL822X_VND2_TO_PAGE (reg) ((reg) >> 4)#define RTL822X_VND2_TO_PAGE_REG (reg) (16 + (((reg) & GENMASK(3,0)) >> 1))
drivers/net/phy/realtek/realtek_main.c +4
-0@@ -271,6 +274,18 @@#define RTL8261X_INT_ALDPS_CHG BIT(9)#define RTL8261X_INT_JABBER BIT(10) +/* SerDes lane polarity, behind the VEND1 SerDes command window. This +is not +* the global inversion bit that other Realtek 10G PHYs use; the bit +* assignment below has only been verified on an RTL8261CE reporting drivers/net/phy/realtek/realtek_main.c line 290
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+PHY ID +* 0x001cc899. +*/ +#define RTL8261X_SERDES_POL_REG0 0x0000 +#define RTL8261X_SERDES_POL_REG0_TX BIT(8) +#define RTL8261X_SERDES_POL_REG0_RX BIT(9) +#define RTL8261X_SERDES_POL_REGC2 0x00c2 +#define RTL8261X_SERDES_POL_REGC2_TX BIT(14) #define +RTL8261X_SERDES_POL_REGC2_RX BIT(13) +Hi,
Thanks for submitting this patch.
The serdes registers modified in this patch are not unified across RTL8261 family. This patch will lead to undefined behaviors on other IC. And operating these SerDes registers requires a specific hardware control flow. The direct manipulation used in this patch will introduce unknown risk.
Therefore, we kindly suggest drop this patch.
BRS,
Javen
RE: [PATCH net-next 3/3] net: phy: realtek: add LED support for RTL8261C/D
In reply to JavenResending text-encoded:
Hi Javen,
Thanks for reviewing.
Could you clarify "configured via firmware"? Neither rtl8261c.bin nor rtl8261d.bin in linux-firmware writes the LED block (0xd032 + 2 * index, 0xd040, 0xd044), directly or through the 0xa436/0xa438 window.
The driver already configures LEDs from the kernel on the RTL8211E/F and RTL8221B, and the RTL8221B uses the same VEND2 block this patch drives.
The layout was confirmed on an RTL8261CE here, and Chad (CC'd) reports it working on RTL8261C and RTL8261D boards. If it differs on a variant the driver binds, which one? I'll restrict the callbacks accordingly.
Simon
Am 28. September 2026 09:23:37 MESZ schrieb Javen <[email protected]>:
Quoted 80 lines
Quoted 67 lines
The RTL8261C/D use the same LED register block as the RTL8221B: one control register per LED at VEND2
0xd032+ 2 * index selecting the link speeds that light it, activity blink bits in LCR6 and per-LED polarity and enable bits in LCR7. Compared to the RTL8221B there are four LEDs instead of three, and two more speed bits for 5G and 10G.Reuse the existing RTL822X_VND2_* definitions and add the two speed bits and the enable bit. The callbacks follow rtl822xb_led_*() closely, with two additions:
-
led_polarity_set()honours active-low LEDs. The polarity bit in LCR7 doubles as the manual on/off level inled_brightness_set(), so the configured polarity is cached in the private data and restored byled_hw_control_set().-
led_hw_control_set()andled_brightness_set()set the output enable bit, which firmware normally leaves set already.The callbacks duplicate most of rtl822xb_led_*(), differing only in the LED count, the speed mask and the LCR7 handling. Making the RTL8221B code table-driven and sharing it would be the right end state, but that touches a working driver and wants testing on an RTL8221B, so it is left for a follow-up series.
The callbacks are wired to the
RTL8261C_CGandRTL8261CE_CGentries, which between them cover the parts this was tested on.RTL8261D_VMis left out for lack of hardware.Tested on a Gemtek W1700K (Airoha AN7581) with an RTL8261CE: index 2 drives a yellow and index 3 a green LED on each 10G port. Under hardware control the link speed bits, the activity blink and the combined
TRIGGER_NETDEV_LINKall take effect and offloading is confirmed through the netdev trigger. The polarity bit was verified to be active-high when clear on that board. Also tested on AN7581 and MT7988A boards with an RTL8261C and RTL8261D.Signed-off-by Chad Monroe <[email protected]>Co-developed-by Simon Polack <[email protected]>Signed-off-by Simon Polack <[email protected]>Assisted-by LLM---
drivers/net/phy/realtek/realtek_main.c| 228
+++++++++++++++++++++++++1 file changed, 228 insertions(+)drivers/net/phy/realtek/realtek_main.c +3
-0@@ -183,12 +183,15 @@#define RTL822X_VND2_LCR_LINK_100 BIT(1)#define RTL822X_VND2_LCR_LINK_1000 BIT(2)#define RTL822X_VND2_LCR_LINK_2500 BIT(5) +#define RTL822X_VND2_LCR_LINK_5000 BIT(6) +#define RTL822X_VND2_LCR_LINK_10000 BIT(4)#define RTL822X_VND2_LCR6 0xd040#define RTL822X_VND2_LED_ACT (x) BIT(x)#define RTL822X_VND2_LCR7 0xd044#define RTL822X_VND2_LED_POLAR (x) BIT(x) +#define RTL822X_VND2_LED_EN (x) BIT((x) + 4)#define RTL8224_MII_RTCT 0x11#define RTL8224_MII_RTCT_ENABLE BIT(0)drivers/net/phy/realtek/realtek_main.c line 311
Quoted 4 lines
drivers/net/phy/realtek/realtek_main.c +1
-0@@ -305,6 +308,7 @@#define FW_SUB_MAGIC_8261D 0x32363144#define RTL8261X_POLL_TIMEOUT_MS 100#define RTL8261X_MAX_MMD_DEV 31 +#define RTL8261X_LED_COUNT 4Hi,
We kindly suggest dropping this patch for the same reason as in Patch 2/3.
LED config is related to HW config and will be configured via firmware.
BRs,
Javen