netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net: phy: realtek: add combo mode support for RTL8211FS
@ 2024-12-02 19:50 Zhiyuan Wan
  2024-12-02 19:50 ` [PATCH 2/2] net: phy: realtek: add dt property to disable broadcast PHY address Zhiyuan Wan
  2024-12-02 23:52 ` [PATCH 1/2] net: phy: realtek: add combo mode support for RTL8211FS Andrew Lunn
  0 siblings, 2 replies; 19+ messages in thread
From: Zhiyuan Wan @ 2024-12-02 19:50 UTC (permalink / raw)
  To: andrew; +Cc: kuba, netdev, linux-kernel, willy.liu, Zhiyuan Wan, Yuki Lee

The RTL8211FS chip is an ethernet transceiver with both copper MDIX and
optical (SGMII) port, and it has ability to switch between copper and
optical mode (combo mode).

On Linux kernel v6.12.1, the driver doesn't support negotiation port mode,
which causes optical mode unusable, and copper mode works fine.

This patch solved the issue above by add negotiation phase for this
transceiver chip, allows this transceiver works in combo mode.

Signed-off-by: Yuki Lee <febrieac@outlook.com>
Signed-off-by: Zhiyuan Wan <kmlinuxm@gmail.com>
---
 drivers/net/phy/realtek.c | 67 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index f65d7f1f3..10a87d58c 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -32,6 +32,11 @@
 #define RTL8211F_PHYCR2				0x19
 #define RTL8211F_INSR				0x1d
 
+#define RTL8211FS_FIBER_ESR			0x0F
+#define RTL8211FS_MODE_MASK			0xC000
+#define RTL8211FS_MODE_COPPER			0
+#define RTL8211FS_MODE_FIBER			1
+
 #define RTL8211F_LEDCR				0x10
 #define RTL8211F_LEDCR_MODE			BIT(15)
 #define RTL8211F_LEDCR_ACT_TXRX			BIT(4)
@@ -110,6 +115,7 @@ struct rtl821x_priv {
 	u16 phycr1;
 	u16 phycr2;
 	bool has_phycr2;
+	int lastmode;
 	struct clk *clk;
 };
 
@@ -163,6 +169,44 @@ static int rtl821x_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static int rtl8211f_mode(struct phy_device *phydev)
+{
+	u16 val;
+
+	val = __phy_read(phydev, RTL8211FS_FIBER_ESR);
+	val &= RTL8211FS_MODE_MASK;
+
+	if (val)
+		return RTL8211FS_MODE_FIBER;
+	else
+		return RTL8211FS_MODE_COPPER;
+}
+
+static int rtl8211f_config_aneg(struct phy_device *phydev)
+{
+	int ret;
+
+	struct rtl821x_priv *priv = phydev->priv;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret < 0)
+		return ret;
+
+	linkmode_copy(phydev->advertising, phydev->supported);
+
+	if (rtl8211f_mode(phydev) == RTL8211FS_MODE_FIBER) {
+		dev_dbg(&phydev->mdio.dev, "fiber link up");
+		priv->lastmode = RTL8211FS_MODE_FIBER;
+		return genphy_c37_config_aneg(phydev);
+	}
+
+	dev_dbg(&phydev->mdio.dev, "copper link up");
+
+	priv->lastmode = RTL8211FS_MODE_COPPER;
+
+	return genphy_config_aneg(phydev);
+}
+
 static int rtl8201_ack_interrupt(struct phy_device *phydev)
 {
 	int err;
@@ -732,6 +776,26 @@ static int rtlgen_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int rtl8211f_read_status(struct phy_device *phydev)
+{
+	int ret;
+	struct rtl821x_priv *priv = phydev->priv;
+	bool changed = false;
+
+	if (rtl8211f_mode(phydev) != priv->lastmode) {
+		changed = true;
+		ret = rtl8211f_config_aneg(phydev);
+		if (ret < 0)
+			return ret;
+
+		ret = genphy_restart_aneg(phydev);
+		if (ret < 0)
+			return ret;
+	}
+
+	return genphy_c37_read_status(phydev, &changed);
+}
+
 static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
 {
 	int ret;
@@ -1375,7 +1439,8 @@ static struct phy_driver realtek_drvs[] = {
 		.name		= "RTL8211F Gigabit Ethernet",
 		.probe		= rtl821x_probe,
 		.config_init	= &rtl8211f_config_init,
-		.read_status	= rtlgen_read_status,
+		.config_aneg	= rtl8211f_config_aneg,
+		.read_status	= rtl8211f_read_status,
 		.config_intr	= &rtl8211f_config_intr,
 		.handle_interrupt = rtl8211f_handle_interrupt,
 		.suspend	= rtl821x_suspend,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] net: phy: realtek: add dt property to disable broadcast PHY address
@ 2024-12-03  2:37 万致远
  2024-12-03  2:54 ` Andrew Lunn
  0 siblings, 1 reply; 19+ messages in thread
From: 万致远 @ 2024-12-03  2:37 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: kuba, netdev, linux-kernel, willy.liu, Yuki Lee

On 2024/12/3 8:04, Andrew Lunn wrote:
> On Tue, Dec 03, 2024 at 03:50:29AM +0800, Zhiyuan Wan wrote:
>> This patch add support to disable 'broadcast PHY address' feature of
>> RTL8211F.
>>
>> This feature is enabled defaultly after a reset of this transceiver.
>> When this feature is enabled, the phy not only responds to the
>> configuration PHY address by pin states on board, but also responds
>> to address 0, the optional broadcast address of the MDIO bus.
>>
>> But not every transceiver supports this feature, when RTL8211
>> shares one MDIO bus with other transceivers which doesn't support
>> this feature, like mt7530 switch chip (integrated in mt7621 SoC),
>> it usually causes address conflict, leads to the
>> port of RTL8211FS stops working.
>
> I think you can do this without needing a new property. The DT binding
> has:
>
>             reg = <4>;
>
> This is the address the PHY should respond on. If reg is not 0, then
> broadcast is not wanted.
>
First, broadcast has no relationship with PHY address, it allows MAC
broadcast command to all supported PHY on the MDIO bus.

I can't assume that there's no user use this feature to configure multiple
PHY devices (e.g. there's like 3 or more PHYs on board, their address
represented as 1, 2, 3. When this feature is enabled (default behavior),
users can send commands to address 0 to configure common parameters shared
by these PHYs) at the same time. And they can configure each PHY by it's
own address without influencing other PHY too.

> If reg is 0, it means one of two things:
>
> The DT author did not know about this broadcast feature, the PHY
> appeared at address 0, so they wrote that. It might actually be
> strapped to another address, but it does not matter.
>
Well, that's possible. A misconfiguration on DT with only ONE PHY may
just works, if we disable this feature by default, may cause some device
stops working.

> The DT author wants it to use the broadcast address, it might even be
> strapped to address 0.
>
Again, the broadcast address is shared by all PHYs on MDIO which
support this feature, it's handy for MAC to change multiple PHYs
setting at the same time. But each PHY must have their own address,
and the address usually can't be broadcast address (0).

> Am i missing anything?
>
>       Andrew

I would recommend to add this feature, because it doesn't change the
behavior of this driver, and allows this PHY works together with
other PHY or switch chip which don't support this feature, like mt7530 or
Marvell ones.

Sincerely,

Zhiyuan Wan

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-12-03  9:52 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02 19:50 [PATCH 1/2] net: phy: realtek: add combo mode support for RTL8211FS Zhiyuan Wan
2024-12-02 19:50 ` [PATCH 2/2] net: phy: realtek: add dt property to disable broadcast PHY address Zhiyuan Wan
2024-12-03  0:04   ` Andrew Lunn
2024-12-03  3:46     ` [PATCH v2 1/2] net: phy: realtek: disable broadcast address feature of rtl8211f Zhiyuan Wan
2024-12-03  3:58       ` Andrew Lunn
2024-12-03  4:26         ` [PATCH v3 " Zhiyuan Wan
2024-12-03  6:50           ` Heiner Kallweit
2024-12-03  7:18             ` [PATCH net-next " Zhiyuan Wan
2024-12-03  7:38               ` Heiner Kallweit
2024-12-03  8:35                 ` Zhiyuan Wan
2024-12-03  9:52                   ` Heiner Kallweit
2024-12-02 23:52 ` [PATCH 1/2] net: phy: realtek: add combo mode support for RTL8211FS Andrew Lunn
2024-12-03  3:08   ` 万致远
2024-12-03  3:53     ` Andrew Lunn
2024-12-03  4:42       ` 万致远
2024-12-03  4:44       ` 万致远
  -- strict thread matches above, loose matches on Subject: below --
2024-12-03  2:37 [PATCH 2/2] net: phy: realtek: add dt property to disable broadcast PHY address 万致远
2024-12-03  2:54 ` Andrew Lunn
2024-12-03  3:21   ` 万致远

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).