net: phy: realtek: pair order and polarity
Subsystems (4)
v8 cover net: phy: realtek: pair order and polarity
The RTL8224 PHY gives the manufacturer some flexbility with the pair order and polarity to ease the wiring on the PCB. Then the correct pair order and pair polarity must be provided to the PHY to function properly. This series adds the support to configure the pair order and the pair polarity to the Realtek PHY driver.
---
Changes in v8:
- drivers/net/phy/realtek/realtek_main.c: introduce the common helper in patch 2/4 instead of 4/4.
Changes in v7:
- drivers/net/phy/realtek/realtek_main.c: factor out a common helper for package bit modifications.
Damien Dejean (4):
dt-bindings: net: ethernet-phy: add property enet-phy-pair-order
net: phy: realtek: add RTL8224 pair order support
dt-bindings: net: ethernet-phy: add property enet-phy-pair-polarity
net: phy: realtek: add RTL8224 polarity support
.../devicetree/bindings/net/ethernet-phy.yaml | 14 +++ drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 96 +++++++++++++++++++ 3 files changed, 111 insertions(+)
Signature · 1 line
2.47.3
PATCH v8 1/4 dt-bindings: net: ethernet-phy: add property enet-phy-pair-order
Add property enet-phy-pair-order to the device tree bindings to define the pair 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 pair order (ABCD), or 1 to force the reverse pair order (DCBA).
--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +6 -0
@@ -126,6 +126,12 @@ properties: e.g. wrong bootstrap configuration caused by issues in PCB layout design. + enet-phy-pair-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:
Signature · 1 line
2.47.3
PATCH v8 2/4 net: phy: realtek: add RTL8224 pair order support
In reply to Damien DejeanThe 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-pair-order. The property is set to 0 to keep the default order (ABCD), or 1 to reverse the pairs (DCBA).
--- drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 64 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
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_PACKAGE help Currently supports RTL821x/RTL822x and fast ethernet PHYs
drivers/net/phy/realtek/realtek_main.c +64 -0
82 lines not on this page · raw message
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [net-next,v8,2/4] net: phy: realtek: add RTL8224 pair order support
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
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.
Quoted 4 lines
drivers/net/phy/realtek/Kconfig +0
-0
[ ... ]
Quoted 4 lines
drivers/net/phy/realtek/realtek_main.c +0
-0
[ ... ]
Quoted 29 lines
drivers/net/phy/realtek/realtek_main.c +25
-0@@ -1820,6 +1822,66 @@ static int rtl8224_cable_test_get_status(struct phy_device *phydev, bool *finishreturn rtl8224_cable_test_report (phydev, finished); } +static int rtl8224_package_modify_mmd (struct phy_device *phydev,int devad, +u32 regnum,u16 mask,u16 set) +{ +int val, ret; + +phy_lock_mdio_bus (phydev); + + val =__phy_package_read_mmd (phydev,0 , devad, regnum); +if (val <0 ) { + ret = val; + goto exit; + } + + val &= ~mask; + val |= set; + + ret =__phy_package_write_mmd (phydev,0 , devad, regnum, val); + +exit: +phy_unlock_mdio_bus (phydev); +return ret; +} + +static int rtl8224_mdi_config_order (struct phy_device *phydev) +{
drivers/net/phy/realtek/realtek_main.c static int rtl8224_cable_test_get_status(struct phy_device *phydev, bool *finish · line 1859
Quoted 10 lines
drivers/net/phy/realtek/realtek_main.c +10
-0+struct device_node *np = phydev->mdio.dev.of_node; +u8 port_offset = phydev->mdio.addr &3 ; +u32 order =0 ; +int ret; + + ret =of_property_read_u32 (np,"enet-phy-pair-order" , &order); + +/* Do nothing in case the property is not present */ +if (ret == -EINVAL ) +return 0 ;
Does this handle the CONFIG_OF=n case correctly?
When CONFIG_OF is disabled, of_property_read_u32() returns -ENOSYS (see include/linux/of.h:736), not -EINVAL. The check above only handles -EINVAL, so the subsequent error check propagates -ENOSYS:
static int rtl8224_mdi_config_order(struct phy_device *phydev)
{
...
ret = of_property_read_u32(np, "enet-phy-pair-order", &order);
if (ret == -EINVAL)
return 0;
if (ret)
return ret; /* -ENOSYS propagates here */
...
}This causes rtl8224_config_init() to return -ENOSYS, which then propagates through phy_init_hw(), failing RTL8224 PHY initialization on non-OF kernel configurations.
REALTEK_PHY has no 'depends on OF' in its Kconfig, so CONFIG_OF=n is a valid build configuration. Before this patch, RTL8224 had no config_init callback, so this is a new failure path.
Could the code handle -ENOSYS in addition to -EINVAL, or use device_property_read_u32() which is firmware-agnostic?
Quoted 17 lines
drivers/net/phy/realtek/realtek_main.c +17
-0+ +if (ret) +return ret; + +if (order & ~1 ) +return -EINVAL ; + +return rtl8224_package_modify_mmd (phydev,MDIO_MMD_VEND1 , +RTL8224_VND1_MDI_PAIR_SWAP , +BIT (port_offset), + order ?BIT (port_offset) :0 ); +} + +static int rtl8224_config_init (struct phy_device *phydev) +{ +return rtl8224_mdi_config_order (phydev); +}
[ ... ]
Signature · 1 line
pw-bot: cr
Re: [net-next,v8,2/4] net: phy: realtek: add RTL8224 pair order support
Quoted 11 lines · Jakub Kicinski
This causes
rtl8224_config_init()to return-ENOSYS, which then propagates throughphy_init_hw(), failing RTL8224 PHY initialization on non-OF kernel configurations.
REALTEK_PHYhas no 'depends on OF' in itsKconfig, soCONFIG_OF=nis a valid build configuration. Before this patch, RTL8224 had noconfig_initcallback, so this is a new failure path.Could the code handle
-ENOSYSin addition to-EINVAL, or usedevice_property_read_u32()which is firmware-agnostic?
Thanks for the feedback, I handled ENOSYS next to EINVAL in the v9 series.
Regards,
Damien
PATCH v8 3/4 dt-bindings: net: ethernet-phy: add property enet-phy-pair-polarity
In reply to Damien DejeanAdd the property enet-phy-pair-polarity to describe the polarity of the PHY pairs. 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-pair-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.
--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +8 -0
@@ -132,6 +132,14 @@ properties: description: For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA). + enet-phy-pair-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:
Signature · 1 line
2.47.3
PATCH v8 4/4 net: phy: realtek: add RTL8224 polarity support
In reply to Damien DejeanThe 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-pair-polarity. The u32 value is a bitfield where bit[0..3] control the polarity of pairs A..D.
--- drivers/net/phy/realtek/realtek_main.c | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/net/phy/realtek/realtek_main.c +33 -1
@@ -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)
@@ -1870,9 +1871,40 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev) order ? BIT(port_offset) : 0); } +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 ; +u32 polarity =0 ; +int ret; + + ret =of_property_read_u32 (np,"enet-phy-pair-polarity" , &polarity); + +/* Do nothing if the property is not present */ +if (ret == -EINVAL ) +return 0 ; + +if (ret) +return ret; + +if (polarity & ~0xf ) +return -EINVAL ; + +return rtl8224_package_modify_mmd (phydev,MDIO_MMD_VEND1 , +RTL8224_VND1_MDI_POLARITY_SWAP , +0xf << offset, + polarity << offset); +} +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)
Signature · 1 line
2.47.3