* [PATCH net] net: phy: realtek: fix RTL8224 package address selection
@ 2026-10-04 20:46 Oskari Lemmela
2026-10-05 14:00 ` Andrew Lunn
0 siblings, 1 reply; 3+ messages in thread
From: Oskari Lemmela @ 2026-10-04 20:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Damien Dejean
Cc: Manuel Stocker, Oskari Lemmela, netdev, linux-kernel
From: Manuel Stocker <mensi@mensi.ch>
The RTL8224 driver rounds each PHY address down to a multiple of four
to select the package base and uses the low two address bits as the
port index. For a package starting at an unaligned MDIO address, this
accesses shared registers at the wrong address and selects incorrect
MDI pair order and polarity fields.
The Hasivo S1100WP-8GT-2S+ uses two RTL8224 packages at MDIO
addresses 1-4 and 5-8. The aligned-address assumption splits each
physical package into incorrect software groups rather than using
the actual package bases of 1 and 5.
Use the base address from an ethernet-phy-package node when present
and calculate each port's offset relative to that address. Reject
PHY addresses outside the four-port package and propagate explicit
package errors instead of falling back to another base address.
Keep the existing aligned-address assumption when no package node
is present.
Fixes: 330296ea9e15 ("net: phy: realtek: add RTL8224 pair order support")
Signed-off-by: Manuel Stocker <mensi@mensi.ch>
[Oskari: rebased on net/main, reworded commit message]
Signed-off-by: Oskari Lemmela <oskari@lemmela.net>
---
drivers/net/phy/realtek/realtek_main.c | 49 +++++++++++++++++++++++---
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 177b62a7b2d1..8405a74d631f 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -340,6 +340,10 @@ struct rtl821x_priv {
u16 iner;
};
+struct rtl8224_priv {
+ u8 port_offset;
+};
+
struct rtl8261x_priv {
const char *fw_name;
bool fw_loaded;
@@ -2699,7 +2703,8 @@ static int rtl8224_package_modify_mmd(struct phy_device *phydev, int devad,
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;
+ struct rtl8224_priv *priv = phydev->priv;
+ u8 port_offset = priv->port_offset;
u32 order = 0;
int ret;
@@ -2724,7 +2729,8 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev)
static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
{
struct device_node *np = phydev->mdio.dev.of_node;
- u8 offset = (phydev->mdio.addr & 3) * 4;
+ struct rtl8224_priv *priv = phydev->priv;
+ u8 offset = priv->port_offset * 4;
u32 polarity = 0;
int ret;
@@ -2759,9 +2765,42 @@ static int rtl8224_config_init(struct phy_device *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);
+ struct device *dev = &phydev->mdio.dev;
+ u32 base_addr = phydev->mdio.addr & ~3;
+ struct rtl8224_priv *priv;
+ struct device_node *np;
+ int ret;
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ np = of_get_parent(dev->of_node);
+ if (of_node_name_eq(np, "ethernet-phy-package")) {
+ ret = of_property_read_u32(np, "reg", &base_addr);
+ of_node_put(np);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Missing or invalid PHY package reg\n");
+
+ if (phydev->mdio.addr < base_addr ||
+ phydev->mdio.addr - base_addr >= 4)
+ return dev_err_probe(dev, -EINVAL,
+ "PHY address outside RTL8224 package\n");
+
+ ret = devm_of_phy_package_join(dev, phydev, 0);
+ } else {
+ of_node_put(np);
+ /* Without a package node, assume four aligned PHY addresses. */
+ ret = devm_phy_package_join(dev, phydev, base_addr, 0);
+ }
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to join PHY package\n");
+
+ priv->port_offset = phydev->mdio.addr - base_addr;
+ phydev->priv = priv;
+
+ return 0;
}
static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
base-commit: 6dc989ea46b96ce170840174b4a38c4a387fb005
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: phy: realtek: fix RTL8224 package address selection
2026-10-04 20:46 [PATCH net] net: phy: realtek: fix RTL8224 package address selection Oskari Lemmela
@ 2026-10-05 14:00 ` Andrew Lunn
2026-10-05 17:27 ` Oskari Lemmelä
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2026-10-05 14:00 UTC (permalink / raw)
To: Oskari Lemmela
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Damien Dejean, Manuel Stocker,
netdev, linux-kernel
On Sun, Oct 04, 2026 at 11:46:36PM +0300, Oskari Lemmela wrote:
> From: Manuel Stocker <mensi@mensi.ch>
>
> The RTL8224 driver rounds each PHY address down to a multiple of four
> to select the package base and uses the low two address bits as the
> port index. For a package starting at an unaligned MDIO address, this
> accesses shared registers at the wrong address and selects incorrect
> MDI pair order and polarity fields.
>
> The Hasivo S1100WP-8GT-2S+ uses two RTL8224 packages at MDIO
> addresses 1-4 and 5-8. The aligned-address assumption splits each
> physical package into incorrect software groups rather than using
> the actual package bases of 1 and 5.
>
> Use the base address from an ethernet-phy-package node when present
> and calculate each port's offset relative to that address. Reject
> PHY addresses outside the four-port package and propagate explicit
> package errors instead of falling back to another base address.
>
> Keep the existing aligned-address assumption when no package node
> is present.
>
> Fixes: 330296ea9e15 ("net: phy: realtek: add RTL8224 pair order support")
I suggest this gets merged to net-next. It never worked, so it is not
a regression. This patch just extends the current implementation to be
more generic.
And now you are looking at DT properties, you need a DT binding
document.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: phy: realtek: fix RTL8224 package address selection
2026-10-05 14:00 ` Andrew Lunn
@ 2026-10-05 17:27 ` Oskari Lemmelä
0 siblings, 0 replies; 3+ messages in thread
From: Oskari Lemmelä @ 2026-10-05 17:27 UTC (permalink / raw)
To: Andrew Lunn
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Damien Dejean, Manuel Stocker,
netdev, linux-kernel
On 10/5/26 17:00, Andrew Lunn wrote:
>>
>> Fixes: 330296ea9e15 ("net: phy: realtek: add RTL8224 pair order support")
>
> I suggest this gets merged to net-next. It never worked, so it is not
> a regression. This patch just extends the current implementation to be
> more generic.
Thanks for the review and clarification. I'll prepare v2 against
net-next, remove the Fixes tag, and update the commit message to
describe this as extending support to unaligned PHY packages.
> And now you are looking at DT properties, you need a DT binding
> document.
I'll include the RTL8224 PHY package binding documentation as a
separate patch in the series.
Regards,
Oskari
>
> Andrew
>
> ---
> pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-05 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-04 20:46 [PATCH net] net: phy: realtek: fix RTL8224 package address selection Oskari Lemmela
2026-10-05 14:00 ` Andrew Lunn
2026-10-05 17:27 ` Oskari Lemmelä
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox