* [PATCH v4 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order
@ 2026-01-29 10:16 Damien Dejean
2026-01-29 10:16 ` [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Damien Dejean @ 2026-01-29 10:16 UTC (permalink / raw)
To: andrew, krzk+dt, robh, kuba
Cc: netdev, devicetree, linux-kernel, edumazet, davem, pabeni,
hkallweit1, Damien Dejean
Add property enet-phy-lane-order to the device tree bindings to define
the lane order of the PHY. To simplify PCB design some manufacturers
allow to wire the pairs in a reverse order, and change the order in
software.
The property can be set to 0 to force the normal lane order (ABCD), or 1
to force the reverse lane order (DCBA).
Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
---
Documentation/devicetree/bindings/net/ethernet-phy.yaml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
index 58634fee9fc4..8347d4e134d2 100644
--- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
@@ -126,6 +126,12 @@ properties:
e.g. wrong bootstrap configuration caused by issues in PCB
layout design.
+ enet-phy-lane-order:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1]
+ description:
+ For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA).
+
eee-broken-100tx:
$ref: /schemas/types.yaml#/definitions/flag
description:
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support
2026-01-29 10:16 [PATCH v4 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Damien Dejean
@ 2026-01-29 10:16 ` Damien Dejean
2026-01-31 1:53 ` [v4,2/4] " Jakub Kicinski
2026-01-29 10:16 ` [PATCH v4 3/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity Damien Dejean
2026-01-29 10:16 ` [PATCH v4 4/4] net: phy: realtek: add RTL8224 polarity support Damien Dejean
2 siblings, 1 reply; 6+ messages in thread
From: Damien Dejean @ 2026-01-29 10:16 UTC (permalink / raw)
To: andrew, krzk+dt, robh, kuba
Cc: netdev, devicetree, linux-kernel, edumazet, davem, pabeni,
hkallweit1, Damien Dejean
The RTL8224 has a register to configure a pair swap (from ABCD order to
DCBA) providing PCB designers more flexbility when wiring the chip. The
swap parameter has to be set correctly for each of the 4 ports before
the chip can detect a link.
After a reset, this register is (unfortunately) left in a random state,
thus it has to be initialized. On most of the devices the bootloader
does it once for all and we can rely on the value set, on some other it
is not and the kernel has to do it.
The MDI pair swap can be set in the device tree using the property
enet-phy-lane-order. The property is set to 0 to keep the default order
(ABCD), or 1 to reverse the pairs (DCBA).
Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
---
drivers/net/phy/realtek/Kconfig | 1 +
drivers/net/phy/realtek/realtek_main.c | 49 ++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/drivers/net/phy/realtek/Kconfig b/drivers/net/phy/realtek/Kconfig
index b05c2a1e9024..a741b34d193e 100644
--- a/drivers/net/phy/realtek/Kconfig
+++ b/drivers/net/phy/realtek/Kconfig
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
config REALTEK_PHY
tristate "Realtek PHYs"
+ select PHY_PACKAGE
help
Currently supports RTL821x/RTL822x and fast ethernet PHYs
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 75565fbdbf6d..79c2762b610e 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -171,6 +171,8 @@
#define RTL8224_SRAM_RTCT_LEN(pair) (0x8028 + (pair) * 4)
+#define RTL8224_VND1_MDI_PAIR_SWAP 0xa90
+
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)
@@ -1820,6 +1822,51 @@ static int rtl8224_cable_test_get_status(struct phy_device *phydev, bool *finish
return rtl8224_cable_test_report(phydev, finished);
}
+static int rtl8224_mdi_config_order(struct phy_device *phydev)
+{
+ struct device_node *np = phydev->mdio.dev.of_node;
+ u8 port_offset = phydev->mdio.addr & 3;
+ u32 order = 0;
+ int ret, val;
+
+ ret = of_property_read_u32(np, "enet-phy-lane-order", &order);
+
+ /* Do nothing in case the property is not present */
+ if (ret == -EINVAL)
+ return 0;
+
+ if (ret)
+ return ret;
+
+ if (order & ~1)
+ return -EINVAL;
+
+ val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_PAIR_SWAP);
+ if (val < 0)
+ return val;
+
+ if (order)
+ val |= (1 << port_offset);
+ else
+ val &= ~(1 << port_offset);
+
+ return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_PAIR_SWAP, val);
+}
+
+static int rtl8224_config_init(struct phy_device *phydev)
+{
+ return rtl8224_mdi_config_order(phydev);
+}
+
+static int rtl8224_probe(struct phy_device *phydev)
+{
+ /* Chip exposes 4 ports, join all of them in the same package */
+ return devm_phy_package_join(&phydev->mdio.dev, phydev,
+ phydev->mdio.addr & ~3, 0);
+}
+
static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
{
int val;
@@ -2392,6 +2439,8 @@ static struct phy_driver realtek_drvs[] = {
PHY_ID_MATCH_EXACT(0x001ccad0),
.name = "RTL8224 2.5Gbps PHY",
.flags = PHY_POLL_CABLE_TEST,
+ .probe = rtl8224_probe,
+ .config_init = rtl8224_config_init,
.get_features = rtl822x_c45_get_features,
.config_aneg = rtl822x_c45_config_aneg,
.read_status = rtl822x_c45_read_status,
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 3/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity
2026-01-29 10:16 [PATCH v4 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Damien Dejean
2026-01-29 10:16 ` [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
@ 2026-01-29 10:16 ` Damien Dejean
2026-01-29 10:16 ` [PATCH v4 4/4] net: phy: realtek: add RTL8224 polarity support Damien Dejean
2 siblings, 0 replies; 6+ messages in thread
From: Damien Dejean @ 2026-01-29 10:16 UTC (permalink / raw)
To: andrew, krzk+dt, robh, kuba
Cc: netdev, devicetree, linux-kernel, edumazet, davem, pabeni,
hkallweit1, Damien Dejean
Add the property enet-phy-lane-polarity to describe the polarity of the
PHY lanes. To ease PCB designs some manufacturers allow to wire the
pairs with a reverse polarity and provide a way to configure it.
The property 'enet-phy-lane-polarity' sets the polarity of each pair.
Bit 0 to 3 configure the polarity or pairs A to D, if set to 1 the
polarity is reversed for this pair.
Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
---
Documentation/devicetree/bindings/net/ethernet-phy.yaml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
index 8347d4e134d2..67747493352b 100644
--- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
@@ -132,6 +132,14 @@ properties:
description:
For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA).
+ enet-phy-lane-polarity:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ maximum: 0xf
+ description:
+ A bitmap to describe pair polarity swap. Bit 0 to swap polarity of pair A,
+ bit 1 to swap polarity of pair B, bit 2 to swap polarity of pair C and bit
+ 3 to swap polarity of pair D.
+
eee-broken-100tx:
$ref: /schemas/types.yaml#/definitions/flag
description:
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 4/4] net: phy: realtek: add RTL8224 polarity support
2026-01-29 10:16 [PATCH v4 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Damien Dejean
2026-01-29 10:16 ` [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
2026-01-29 10:16 ` [PATCH v4 3/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity Damien Dejean
@ 2026-01-29 10:16 ` Damien Dejean
2026-01-31 1:53 ` [v4,4/4] " Jakub Kicinski
2 siblings, 1 reply; 6+ messages in thread
From: Damien Dejean @ 2026-01-29 10:16 UTC (permalink / raw)
To: andrew, krzk+dt, robh, kuba
Cc: netdev, devicetree, linux-kernel, edumazet, davem, pabeni,
hkallweit1, Damien Dejean
The RTL8224 has a register to configure the polarity of every pair of
each port. It provides device designers more flexbility when wiring the
chip.
Unfortunately, the register is left in an unknown state after a reset.
Thus on devices where the bootloader don't initialize it, the driver has
to do it to detect and use a link.
The MDI polarity swap can be set in the device tree using the property
enet-phy-lane-polarity. The u32 value is a bitfield where bit[0..3]
control the polarity of pairs A..D.
Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
---
drivers/net/phy/realtek/realtek_main.c | 39 +++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 79c2762b610e..8013ba453f05 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -172,6 +172,7 @@
#define RTL8224_SRAM_RTCT_LEN(pair) (0x8028 + (pair) * 4)
#define RTL8224_VND1_MDI_PAIR_SWAP 0xa90
+#define RTL8224_VND1_MDI_POLARITY_SWAP 0xa94
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)
@@ -1855,9 +1856,45 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev)
RTL8224_VND1_MDI_PAIR_SWAP, val);
}
+static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
+{
+ struct device_node *np = phydev->mdio.dev.of_node;
+ u8 port_offset = phydev->mdio.addr & 3;
+ u32 polarity = 0;
+ int ret, val;
+
+ ret = of_property_read_u32(np, "enet-phy-lane-polarity", &polarity);
+
+ /* Do nothing if the property is not present */
+ if (ret == -EINVAL)
+ return 0;
+
+ if (ret)
+ return ret;
+
+ if (polarity & ~0xf)
+ return -EINVAL;
+
+ val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP);
+ if (val < 0)
+ return val;
+
+ val &= ~(0xf << port_offset);
+ val |= polarity << port_offset;
+ return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP, val);
+}
+
static int rtl8224_config_init(struct phy_device *phydev)
{
- return rtl8224_mdi_config_order(phydev);
+ int ret;
+
+ ret = rtl8224_mdi_config_order(phydev);
+ if (ret)
+ return ret;
+
+ return rtl8224_mdi_config_polarity(phydev);
}
static int rtl8224_probe(struct phy_device *phydev)
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [v4,2/4] net: phy: realtek: add RTL8224 pair order support
2026-01-29 10:16 ` [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
@ 2026-01-31 1:53 ` Jakub Kicinski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2026-01-31 1:53 UTC (permalink / raw)
To: dam.dejean
Cc: Jakub Kicinski, robh, krzk+dt, andrew, davem, hkallweit1,
devicetree, linux-kernel, pabeni, netdev, edumazet
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: realtek: add RTL8224 pair order support
This patch adds MDI pair order configuration support for the RTL8224 PHY,
allowing device tree configuration of pair swap (ABCD to DCBA) via the
enet-phy-lane-order property.
> diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
> --- a/drivers/net/phy/realtek/realtek_main.c
> +++ b/drivers/net/phy/realtek/realtek_main.c
[ ... ]
> +static int rtl8224_mdi_config_order(struct phy_device *phydev)
> +{
> + struct device_node *np = phydev->mdio.dev.of_node;
> + u8 port_offset = phydev->mdio.addr & 3;
> + u32 order = 0;
> + int ret, val;
> +
> + ret = of_property_read_u32(np, "enet-phy-lane-order", &order);
> +
> + /* Do nothing in case the property is not present */
> + if (ret == -EINVAL)
> + return 0;
> +
> + if (ret)
> + return ret;
> +
> + if (order & ~1)
> + return -EINVAL;
> +
> + val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
> + RTL8224_VND1_MDI_PAIR_SWAP);
Should the MDIO bus lock be held before calling __phy_package_read_mmd()?
The __phy_package_read_mmd() documentation states "Same calling rules as
for __phy_read()", and __phy_read() requires: "The caller must have taken
the MDIO bus lock."
Looking at __mdiobus_read(), there is a lockdep_assert_held_once() check
for bus->mdio_lock, which confirms this requirement.
Other PHY drivers using these APIs acquire the lock first. For example,
qca807x_phy_package_config_init_once() wraps its __phy_package_read_mmd()
calls with phy_lock_mdio_bus()/phy_unlock_mdio_bus().
Additionally, since this is a read-modify-write on a shared register that
contains bits for all 4 ports in the package, could concurrent config_init
calls from different ports race and overwrite each other's settings without
the lock protecting the entire sequence?
> + if (val < 0)
> + return val;
> +
> + if (order)
> + val |= (1 << port_offset);
> + else
> + val &= ~(1 << port_offset);
> +
> + return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
> + RTL8224_VND1_MDI_PAIR_SWAP, val);
> +}
--
pw-bot: cr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [v4,4/4] net: phy: realtek: add RTL8224 polarity support
2026-01-29 10:16 ` [PATCH v4 4/4] net: phy: realtek: add RTL8224 polarity support Damien Dejean
@ 2026-01-31 1:53 ` Jakub Kicinski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2026-01-31 1:53 UTC (permalink / raw)
To: dam.dejean
Cc: Jakub Kicinski, robh, krzk+dt, andrew, davem, hkallweit1,
devicetree, linux-kernel, pabeni, netdev, edumazet
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: realtek: add RTL8224 polarity support
This patch adds MDI polarity swap support for RTL8224. The polarity
configuration uses 4 bits per port (one for each pair A-D) and is read
from the device tree property enet-phy-lane-polarity.
> diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
> --- a/drivers/net/phy/realtek/realtek_main.c
> +++ b/drivers/net/phy/realtek/realtek_main.c
[ ... ]
> +static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
> +{
> + struct device_node *np = phydev->mdio.dev.of_node;
> + u8 port_offset = phydev->mdio.addr & 3;
> + u32 polarity = 0;
> + int ret, val;
> +
> + ret = of_property_read_u32(np, "enet-phy-lane-polarity", &polarity);
> +
> + /* Do nothing if the property is not present */
> + if (ret == -EINVAL)
> + return 0;
> +
> + if (ret)
> + return ret;
> +
> + if (polarity & ~0xf)
> + return -EINVAL;
> +
> + val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
> + RTL8224_VND1_MDI_POLARITY_SWAP);
> + if (val < 0)
> + return val;
> +
> + val &= ~(0xf << port_offset);
> + val |= polarity << port_offset;
^^^^^^^^^^^^^^^^^^^^^^^^
The shift amount appears incorrect for a 4-bit-per-port register layout.
Since polarity uses 4 bits (for pairs A-D) and port_offset ranges from
0 to 3, should the shift be (port_offset * 4) rather than just port_offset?
With the current code:
- Port 0 (offset=0): writes to bits 0-3 (correct)
- Port 1 (offset=1): writes to bits 1-4 (overlaps port 0)
- Port 2 (offset=2): writes to bits 2-5 (overlaps ports 0-1)
- Port 3 (offset=3): writes to bits 3-6 (overlaps ports 0-2)
The earlier v1 patch posted to lore used "(phydev->mdio.addr & 3) * 4"
for the offset calculation. Was the multiplication by 4 accidentally
dropped during refactoring?
For comparison, rtl8224_mdi_config_order() uses "1 << port_offset" which
is correct for a 1-bit-per-port layout, but the polarity register needs
4 bits per port.
> + return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
> + RTL8224_VND1_MDI_POLARITY_SWAP, val);
> +}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-01-31 1:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 10:16 [PATCH v4 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Damien Dejean
2026-01-29 10:16 ` [PATCH v4 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
2026-01-31 1:53 ` [v4,2/4] " Jakub Kicinski
2026-01-29 10:16 ` [PATCH v4 3/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity Damien Dejean
2026-01-29 10:16 ` [PATCH v4 4/4] net: phy: realtek: add RTL8224 polarity support Damien Dejean
2026-01-31 1:53 ` [v4,4/4] " Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox