lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260116173920.371523-2-dam.dejean@gmail.com>
Date: Fri, 16 Jan 2026 18:39:20 +0100
From: Damien Dejean <dam.dejean@...il.com>
To: netdev@...r.kernel.org
Cc: Damien Dejean <dam.dejean@...il.com>
Subject: [PATCH 2/2] net: phy: realtek: add RTL8224 polarity swap support

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
realtek,mdi-polarity-swap. The u32 value is a bitfield where bit[0..3]
control the polarity of pairs A...D.

Signed-off-by: Damien Dejean <dam.dejean@...il.com>
---
 .../bindings/net/realtek,rtl82xx.yaml         |  7 +++++
 drivers/net/phy/realtek/realtek_main.c        | 29 +++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml b/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml
index 2d04d90f8b97..4abcc5cfaf5f 100644
--- a/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml
+++ b/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml
@@ -67,6 +67,13 @@ properties:
       - off
     default: keep
 
+  realtek,mdi-polarity-swap:
+    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.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
 unevaluatedProperties: false
 
 allOf:
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index e01bfad37cf5..3bcee2f40a44 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -164,6 +164,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)
@@ -219,6 +220,7 @@ enum pair_swap_state {
 
 struct rtl8224_priv {
 	enum pair_swap_state pair_swap;
+	int polarity_swap;
 };
 
 static int rtl821x_read_page(struct phy_device *phydev)
@@ -1713,12 +1715,28 @@ static void rtl8224_mdi_pair_swap(struct phy_device *phydev, bool swap)
 				RTL8224_VND1_MDI_PAIR_SWAP, val);
 }
 
+static void rtl8224_mdi_polarity_swap(struct phy_device *phydev, u32 swap)
+{
+	u32 val;
+	u8 offset;
+
+	offset = (phydev->mdio.addr & 3) * 4;
+	val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
+				     RTL8224_VND1_MDI_POLARITY_SWAP);
+	val &= ~(0xf << offset);
+	val |= (swap & 0xf) << offset;
+	__phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
+				RTL8224_VND1_MDI_POLARITY_SWAP, val);
+}
+
 static int rtl8224_config_init(struct phy_device *phydev)
 {
 	struct rtl8224_priv *priv = phydev->priv;
 
 	if (priv->pair_swap != PAIR_SWAP_KEEP)
 		rtl8224_mdi_pair_swap(phydev, priv->pair_swap == PAIR_SWAP_ON);
+	if (priv->polarity_swap >= 0)
+		rtl8224_mdi_polarity_swap(phydev, priv->polarity_swap);
 
 	return 0;
 }
@@ -1737,6 +1755,16 @@ static enum pair_swap_state rtlgen_pair_swap_state_get(const struct device_node
 	return PAIR_SWAP_KEEP;
 }
 
+static int rtlgen_polarity_swap_get(const struct device_node *np)
+{
+	u32 polarity;
+
+	if (!of_property_read_u32(np, "realtek,mdi-polarity-swap", &polarity))
+		return polarity;
+
+	return -1;
+}
+
 static int rtl8224_probe(struct phy_device *phydev)
 {
 	struct device *dev = &phydev->mdio.dev;
@@ -1748,6 +1776,7 @@ static int rtl8224_probe(struct phy_device *phydev)
 	phydev->priv = priv;
 
 	priv->pair_swap = rtlgen_pair_swap_state_get(dev->of_node);
+	priv->polarity_swap = rtlgen_polarity_swap_get(dev->of_node);
 
 	/* Device has 4 ports */
 	devm_phy_package_join(dev, phydev, phydev->mdio.addr & (~3), 0);
-- 
2.47.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ