Netdev List
 help / color / mirror / Atom feed
From: Rustam Adilov <adilov@disroot.org>
To: "Linus Walleij" <linusw@kernel.org>,
	"Luiz Angelo Daros de Luca" <luizluca@gmail.com>,
	"Alvin Šipraga" <alvin.sipraga@analog.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Willem de Bruijn" <willemb@google.com>,
	"Simon Horman" <horms@kernel.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Rustam Adilov <adilov@disroot.org>
Subject: [RFC PATCH net-next 6/6] net: phy: realtek: add support for RTL9607C internal PHYs
Date: Fri,  4 Dec 2026 23:25:20 +0500	[thread overview]
Message-ID: <20261204182553.33952-7-adilov@disroot.org> (raw)
In-Reply-To: <20261204182553.33952-1-adilov@disroot.org>

The phy id is 0x001ccac0 for RTL9607C-VA and 0x001cc981 for RTL9607C-VB.

It has the same interrupt handling as on RTL8366RB and a very similar
cable test procedure as RTL8224 PHY.

Just like with RTL8365MB-VC PHYs, RTL9607C's internal PHYs have no MMD
registers and stuff like EEE live in the switch's OCP address instead
and the C22 indirect-MMD is not implemented by this hardware.

But unlike in rtl8365mb phy driver, point the read_mmd/.write_mmd to
rtlgen_read_mmd and rtlgen_write_mmd as it handles the OCP address
conversion using the MDIO_MMD_VEND2 which the mdio bus will happily
take.

Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
 drivers/net/phy/realtek/realtek_main.c | 133 +++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 80efaaddc986..5b01fb1af3fd 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -232,6 +232,10 @@
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
+#define RTL9607C_SRAM_RTCT_FAULT(pair)		(0x802b + (pair) * 4)
+#define RTL9607C_SRAM_RTCT_FAULT_MISMATCH	(BIT(1) | BIT(2))
+#define RTL9607C_SRAM_RTCT_LEN(pair)		(0x802d + (pair) * 4)
+
 #define RTL_PHYSR				MII_RESV2
 #define RTL_PHYSR_DUPLEX			BIT(3)
 #define RTL_PHYSR_SPEEDL			GENMASK(5, 4)
@@ -3175,6 +3179,109 @@ static int rtl8365mb_read_status(struct phy_device *phydev)
 	return genphy_read_status(phydev);
 }
 
+static int rtl9607c_pair_len_get(struct phy_device *phydev, u32 pair)
+{
+	int ret;
+
+	ret = rtl8224_sram_read(phydev, RTL9607C_SRAM_RTCT_LEN(pair));
+	if (ret < 0)
+		return ret;
+
+	return ret * 5 / 4;
+}
+
+static int rtl9607c_cable_test_result_trans(u32 result)
+{
+	if (!(result & RTL8224_SRAM_RTCT_FAULT_DONE))
+		return -EBUSY;
+
+	if (result & RTL8224_SRAM_RTCT_FAULT_OK)
+		return ETHTOOL_A_CABLE_RESULT_CODE_OK;
+
+	if (result & RTL8224_SRAM_RTCT_FAULT_OPEN)
+		return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
+
+	if (result & RTL8224_SRAM_RTCT_FAULT_SAME_SHORT)
+		return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
+
+	if (result & RTL8224_SRAM_RTCT_FAULT_BUSY)
+		return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
+
+	if (result & RTL9607C_SRAM_RTCT_FAULT_MISMATCH)
+		return ETHTOOL_A_CABLE_RESULT_CODE_IMPEDANCE_MISMATCH;
+
+	return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
+}
+
+static int rtl9607c_cable_test_report_pair(struct phy_device *phydev, unsigned int pair)
+{
+	int fault_rslt;
+	int ret;
+
+	ret = rtl8224_sram_read(phydev, RTL9607C_SRAM_RTCT_FAULT(pair));
+	if (ret < 0)
+		return ret;
+
+	fault_rslt = rtl9607c_cable_test_result_trans(ret);
+	if (fault_rslt < 0)
+		return fault_rslt;
+
+	ret = ethnl_cable_test_result(phydev, pair, fault_rslt);
+	if (ret < 0)
+		return ret;
+
+	switch (fault_rslt) {
+	case ETHTOOL_A_CABLE_RESULT_CODE_OPEN:
+	case ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT:
+	case ETHTOOL_A_CABLE_RESULT_CODE_IMPEDANCE_MISMATCH:
+		ret = rtl9607c_pair_len_get(phydev, pair);
+		if (ret < 0)
+			return ret;
+
+		return ethnl_cable_test_fault_length(phydev, pair, ret);
+	default:
+		return  0;
+	}
+}
+
+static int rtl9607c_cable_test_report(struct phy_device *phydev, bool *finished)
+{
+	unsigned int pair;
+	int ret;
+
+	for (pair = ETHTOOL_A_CABLE_PAIR_A; pair <= ETHTOOL_A_CABLE_PAIR_D; pair++) {
+		ret = rtl9607c_cable_test_report_pair(phydev, pair);
+		if (ret == -EBUSY) {
+			*finished = false;
+			return 0;
+		}
+
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int rtl9607c_cable_test_get_status(struct phy_device *phydev, bool *finished)
+{
+	int ret;
+
+	*finished = false;
+
+	ret = phy_read_mmd(phydev, MDIO_MMD_VEND2,
+			   RTL822X_VND2_C22_REG(RTL8224_MII_RTCT));
+	if (ret < 0)
+		return ret;
+
+	if (!(ret & RTL8224_MII_RTCT_DONE))
+		return 0;
+
+	*finished = true;
+
+	return rtl9607c_cable_test_report(phydev, finished);
+}
+
 static struct phy_driver realtek_drvs[] = {
 	{
 		PHY_ID_MATCH_EXACT(0x00008201),
@@ -3521,6 +3628,32 @@ static struct phy_driver realtek_drvs[] = {
 		.soft_reset		= genphy_c45_pma_soft_reset,
 		.suspend		= genphy_c45_pma_suspend,
 		.resume			= genphy_c45_pma_resume,
+	}, {
+		PHY_ID_MATCH_EXACT(0x001ccac0),
+		.name		= "RTL9607C-VA Gigabit Ethernet",
+		.flags = PHY_POLL_CABLE_TEST,
+		/* Interrupt handling analogous to RTL8366RB */
+		.config_intr	= genphy_no_config_intr,
+		.handle_interrupt = genphy_handle_interrupt_no_ack,
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+		.read_mmd	= rtlgen_read_mmd,
+		.write_mmd	= rtlgen_write_mmd,
+		.cable_test_start = rtl8224_cable_test_start,
+		.cable_test_get_status = rtl9607c_cable_test_get_status,
+	}, {
+		PHY_ID_MATCH_EXACT(0x001cc981),
+		.name		= "RTL9607C-VB Gigabit Ethernet",
+		.flags = PHY_POLL_CABLE_TEST,
+		/* Interrupt handling analogous to RTL8366RB */
+		.config_intr	= genphy_no_config_intr,
+		.handle_interrupt = genphy_handle_interrupt_no_ack,
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+		.read_mmd	= rtlgen_read_mmd,
+		.write_mmd	= rtlgen_write_mmd,
+		.cable_test_start = rtl8224_cable_test_start,
+		.cable_test_get_status = rtl9607c_cable_test_get_status,
 	},
 };
 
-- 
2.56.1


      parent reply	other threads:[~2026-12-04 18:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:25 [RFC PATCH net-next 0/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 1/6] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 2/6] net: dsa: realtek: add new mmio interface for drivers Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 3/6] dt-bindings: net: dsa: realtek: add new rtl9607c switch compatible Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 4/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 5/6] net: phy: realtek: use mdio.addr instead of 0 in rtlgen_read/write_vend2 Rustam Adilov
2026-12-04 18:25 ` Rustam Adilov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204182553.33952-7-adilov@disroot.org \
    --to=adilov@disroot.org \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox