* [PATCH net] r8169: handle PHY read errors in RTL8168H/RTL8117 setup
@ 2026-12-05 17:56 Muhammed Sariyildiz
2026-12-05 18:02 ` netdev-bot+sinfo
0 siblings, 1 reply; 2+ messages in thread
From: Muhammed Sariyildiz @ 2026-12-05 17:56 UTC (permalink / raw)
To: netdev
Cc: hkallweit1, nic_swsd, andrew+netdev, davem, edumazet, kuba,
pabeni, Muhammed Sariyildiz
phy_read_paged() returns a negative errno when the PHY register access
fails. A few chip setup paths use the return value as register data
without checking for an error first.
In rtl_hw_start_8168h_1() and rtl_hw_start_8117(), a failed SAW counter
read (-ETIMEDOUT) is masked with 0x3fff and yields a bogus non-zero
count, which is then used to program the 1ms timer in the MAC OCP
register. In rtl8168h_2_hw_phy_config(), a failed TX LPF read is
treated as a valid low-nibble value and used to program another PHY
register.
Treat a failed SAW counter read as a zero count so the existing check
skips the update, and skip the TX LPF adjustment when its read fails.
Both are optional tuning steps, so leaving the defaults in place is
safe.
Fixes: 3ab077d2f405 ("r8169: use phy_read/write instead of rtl_readphy/writephy")
Fixes: 1287723aa139 ("r8169: add support for RTL8117")
Fixes: 8bfdce1defb1 ("r8169: add helper r8168g_phy_param")
Signed-off-by: Muhammed Sariyildiz <asiyee994@gmail.com>
---
drivers/net/ethernet/realtek/r8169_main.c | 12 +++++++++---
drivers/net/ethernet/realtek/r8169_phy_config.c | 17 ++++++++++-------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 1da64c6e39e2..b4600d2a6ac8 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -3905,11 +3905,14 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
rtl_pcie_state_l2l3_disable(tp);
- rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff;
+ rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13);
+ if (rg_saw_cnt < 0)
+ rg_saw_cnt = 0;
+ rg_saw_cnt &= 0x3fff;
if (rg_saw_cnt > 0) {
u16 sw_cnt_1ms_ini;
- sw_cnt_1ms_ini = 16000000/rg_saw_cnt;
+ sw_cnt_1ms_ini = 16000000 / rg_saw_cnt;
sw_cnt_1ms_ini &= 0x0fff;
r8168_mac_ocp_modify(tp, 0xd412, 0x0fff, sw_cnt_1ms_ini);
}
@@ -4043,7 +4046,10 @@ static void rtl_hw_start_8117(struct rtl8169_private *tp)
rtl_pcie_state_l2l3_disable(tp);
if (tp->phydev) {
- rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff;
+ rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13);
+ if (rg_saw_cnt < 0)
+ rg_saw_cnt = 0;
+ rg_saw_cnt &= 0x3fff;
if (rg_saw_cnt > 0) {
u16 sw_cnt_1ms_ini;
diff --git a/drivers/net/ethernet/realtek/r8169_phy_config.c b/drivers/net/ethernet/realtek/r8169_phy_config.c
index 4f1d447136ec..896773c24113 100644
--- a/drivers/net/ethernet/realtek/r8169_phy_config.c
+++ b/drivers/net/ethernet/realtek/r8169_phy_config.c
@@ -798,6 +798,7 @@ static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp,
{
u16 ioffset, rlen;
u32 data;
+ int ret;
r8169_apply_firmware(tp);
@@ -815,13 +816,15 @@ static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp,
phy_write_paged(phydev, 0x0bcf, 0x16, ioffset);
/* Modify rlen (TX LPF corner frequency) level */
- data = phy_read_paged(phydev, 0x0bcd, 0x16);
- data &= 0x000f;
- rlen = 0;
- if (data > 3)
- rlen = data - 3;
- data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12);
- phy_write_paged(phydev, 0x0bcd, 0x17, data);
+ ret = phy_read_paged(phydev, 0x0bcd, 0x16);
+ if (ret >= 0) {
+ data = ret & 0x000f;
+ rlen = 0;
+ if (data > 3)
+ rlen = data - 3;
+ data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12);
+ phy_write_paged(phydev, 0x0bcd, 0x17, data);
+ }
/* disable phy pfm mode */
phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] r8169: handle PHY read errors in RTL8168H/RTL8117 setup
2026-12-05 17:56 [PATCH net] r8169: handle PHY read errors in RTL8168H/RTL8117 setup Muhammed Sariyildiz
@ 2026-12-05 18:02 ` netdev-bot+sinfo
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-12-05 18:02 UTC (permalink / raw)
To: Muhammed Sariyildiz
Cc: netdev, hkallweit1, nic_swsd, andrew+netdev, davem, edumazet,
kuba, pabeni
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 18:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 17:56 [PATCH net] r8169: handle PHY read errors in RTL8168H/RTL8117 setup Muhammed Sariyildiz
2026-12-05 18:02 ` netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox