From: Zhiyuan Wan <kmlinuxm@gmail.com>
To: andrew@lunn.ch
Cc: kuba@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, willy.liu@realtek.com,
Zhiyuan Wan <kmlinuxm@gmail.com>, Yuki Lee <febrieac@outlook.com>
Subject: [PATCH 1/2] net: phy: realtek: add combo mode support for RTL8211FS
Date: Tue, 3 Dec 2024 03:50:28 +0800 [thread overview]
Message-ID: <20241202195029.2045633-1-kmlinuxm@gmail.com> (raw)
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
next reply other threads:[~2024-12-02 19:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 19:50 Zhiyuan Wan [this message]
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 ` 万致远
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=20241202195029.2045633-1-kmlinuxm@gmail.com \
--to=kmlinuxm@gmail.com \
--cc=andrew@lunn.ch \
--cc=febrieac@outlook.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=willy.liu@realtek.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;
as well as URLs for NNTP newsgroup(s).