Netdev List
 help / color / mirror / Atom feed
From: Chih Kai Hsu <hsu.chih.kai@realtek.com>
To: "netdev-bot+sashiko@kernel.org" <netdev-bot+sashiko@kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	nic_swsd <nic_swsd@realtek.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"edumazet@google.com" <edumazet@google.com>,
	"bjorn@mork.no" <bjorn@mork.no>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
	"mail@birger-koblitz.de" <mail@birger-koblitz.de>
Subject: RE: [PATCH net-next v10 11/12] r8152: add TGPHY register access for RTL8157 and RTL8159
Date: Thu, 3 Dec 2026 08:03:40 +0000	[thread overview]
Message-ID: <f9d3a228cccb4929bf8429c5d4018467@realtek.com> (raw)
In-Reply-To: <179610757024.3146.14412805988724383466@kernel.org>

> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 2 · Low: 1
> 
> If you believe none of the issues are legitimate, please reply to each issue of
> Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork know
> by including "pw-bot: cr" as a separate line at the end of your reply (one such
> reply per series is enough).
> 
> - [Medium] If the TGPHY busy bit stays set, set_carrier() retries every
>   100 ms with no limit and no backoff, for as long as the interface is…
> - [Medium] On RTL8157/8159 a single PHY write can now be dropped while
>   later writes still go through.
> - [Low] The commit message says rtl_phy_patch_request() 'releases
>   PATCH_REQUEST when a later step fails, so a failed access does not…
> 
> --
> 
> r8152: add TGPHY register access for RTL8157 and RTL8159
> 
> This patch adds a TGPHY command channel for PHY register access on
> RTL8157 and RTL8159. ocp_reg_read() and ocp_reg_write() now go through
> per-chip rtl_ops.phy_read/phy_write hooks. The PHY accessors and the helpers
> built on them return int, and selected callers act on failures.
> 
> > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index
> > 392b7015f4925..b9586c30c04dd 100644
> > --- a/drivers/net/usb/r8152.c
> > +++ b/drivers/net/usb/r8152.c
> 
> [ ... ]
> 
> > @@ -1911,100 +1958,221 @@ static void ocp_byte_set_bits(struct r8152
> > *tp, u16 type, u16 index, u8 set)
> 
> [ ... ]
> 
> > +static int wait_tgphy_cmd_ready(struct r8152 *tp) {
> > +     u16 ocp_data;
> > +     int ret;
> > +
> > +     ret = read_poll_timeout(ocp_read_word, ocp_data,
> > +                             test_bit(RTL8152_INACCESSIBLE,
> &tp->flags) ||
> > +                             !(ocp_data & TGPHY_CMD_BUSY),
> > +                             2000, 20000, false, tp,
> > +                             MCU_TYPE_USB, USB_TGPHY_CMD);
> > +
> > +     if (ret)
> > +             dev_err_ratelimited(&tp->intf->dev, "TGPHY cmd busy
> > + timeout\n");
> > +
> > +     return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV :
> > +ret; }
> > +
> > +static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data,
> > +bool write) {
> > +     u16 cmd = 0;
> > +     int ret;
> > +
> > +     ret = wait_tgphy_cmd_ready(tp);
> > +     if (ret < 0)
> > +             goto out;
> 
> [Severity: Medium]
> On RTL8157/8159, can a single dropped PHY write now corrupt the PHY patch
> RAM without any error being reported?
> 
> Before this patch, these chips used the OCP window. There, a failed control
> transfer goes through r8152_control_msg() and rtl_set_inaccessible(), which
> blocks every later write. A register sequence therefore either completed or
> stopped.
> 
> Here a busy timeout skips this one access and returns -ETIMEDOUT. The device
> stays accessible, so if the busy bit clears later, the next write goes through.
> 
> The PHY loaders write OCP_SRAM_ADDR once and then stream data words,
> relying on the hardware to auto-increment the address. They ignore every
> return value:
> 
> drivers/net/usb/r8152.c:rtl8152_fw_phy_nc_apply() {
>     ...
>         ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg));
>         for (i = 0; i < num; i++)
>                 ocp_reg_write(tp, OCP_SRAM_DATA,
> __le16_to_cpu(data[i]));
>     ...
> }
> 
> The same pattern appears in rtl8152_fw_phy_union_apply(). It also appears in
> open-coded SRAM/SRAM2 bursts in r8157_hw_phy_cfg() (0x8f9c, 0x8566,
> 0x82c8, 0x82a0) and r8159_hw_phy_cfg() (0x81c4).
> 
> A dropped DATA write would shift every later word down one SRAM address. A
> dropped ADDR write would send the whole block to wherever the address
> pointer was left.
> 
> Nothing reads the data back. rtl8152_apply_firmware() also ignores the errno
> that rtl_pre_ram_code() now returns, and it still records rtl_fw->version and
> logs success.
> 
> The commit message says the sram_*() and hw_phy_cfg callers still ignore the
> status. Could it also mention, or the code prevent, this partial-stream case? It
> was not possible with the OCP path.

Yes, I will mention this in the commit message.

> 
> [ ... ]
> 
> > @@ -4597,36 +4767,52 @@ static inline void rtl_reset_ocp_base(struct
> > r8152 *tp)  static int rtl_phy_patch_request(struct r8152 *tp, bool
> > request, bool wait)  {
> 
> [ ... ]
> 
> > -     for (i = 0; wait && i < 5000; i++) {
> > -             u32 ocp_data;
> > +     if (ret < 0)
> > +             return ret;
> >
> > -             if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
> > -                     return -ENODEV;
> > +     for (i = 0; wait && i < 5000; i++) {
> > +             if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) {
> > +                     ret = -ENODEV;
> > +                     goto err;
> > +             }
> >
> >               usleep_range(1000, 2000);
> > -             ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT);
> > -             if ((ocp_data & PATCH_READY) ^ check)
> > +             ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data);
> > +             if (ret < 0)
> > +                     goto err;
> > +             else if ((ocp_data & PATCH_READY) ^ check)
> >                       break;
> >       }
> >
> 
> [ ... ]
> 
> > +     return 0;
> > +
> > +err:
> > +     if (request)
> > +             rtl_phy_patch_request(tp, false, false);
> > +
> > +     return ret;
> >  }
> 
> [Severity: Low]
> The commit message says:
> 
>   rtl_phy_patch_request() returns the errno of a failed write, and
>   releases PATCH_REQUEST when a later step fails, so a failed access
>   does not leave it asserted.
> 
> Is that guaranteed on this err path?
> 
> The release is an ocp_reg_clr_bits() read-modify-write of
> OCP_PHY_PATCH_CMD. It goes through the same TGPHY channel that just failed,
> and its return value is discarded.
> 
> Suppose the original failure was a busy timeout, for example on the
> OCP_PHY_PATCH_STAT read in the wait loop. The release's own
> wait_tgphy_cmd_ready() would then most likely time out too.
> PATCH_REQUEST would stay set, and the caller would only see the original
> errno.
> 
> The success-path release is also unchecked. This applies to
> rtl_post_ram_code() and to the r8153b, r8156, r8156b, r8157 and r8159
> hw_phy_cfg functions:
> 
>         rtl_phy_patch_request(tp, false, true);
> 
> A dropped clear there would leave the PHY MCU in patch-request mode until
> the next full hw_phy_cfg.
> 
> Could the commit message be reworded, or could the result of the release be
> checked?
> 
> [ ... ]
> 
> > @@ -7240,8 +7482,18 @@ static void set_carrier(struct r8152 *tp)  {
> >       struct net_device *netdev = tp->netdev;
> >       struct napi_struct *napi = &tp->napi;
> > +     int bmsr;
> > +
> > +     bmsr = r8152_mdio_read(tp, MII_BMSR);
> > +     if (bmsr < 0) {
> > +             if (bmsr != -ENODEV) {
> > +                     set_bit(RTL8152_LINK_CHG, &tp->flags);
> > +                     schedule_delayed_work(&tp->schedule, HZ / 10);
> > +             }
> > +             return;
> > +     }
> 
> [Severity: Medium]
> If the TGPHY busy bit stays set on RTL8157/8159, does this retry forever?

The retry should not be there. wait_tgphy_cmd_ready() polls the busy
bit for 20 ms. If that times out, the hardware is in error, so another
attempt only times out again. In v11, set_carrier() returns on a failed
BMSR read and keeps the current state, as in v9, and nothing re-arms.

> 
> wait_tgphy_cmd_ready() returns -ETIMEDOUT without setting
> RTL8152_INACCESSIBLE, so bmsr is never -ENODEV here. The following chain
> then repeats every 100 ms with no retry limit or backoff:
> 
> rtl_work_func_t()
>   set_carrier()
>     r8152_mdio_read(tp, MII_BMSR)
>       rtl_tgphy_access()
>         wait_tgphy_cmd_ready()   -> -ETIMEDOUT
>     set_bit(RTL8152_LINK_CHG, &tp->flags)
>     schedule_delayed_work(&tp->schedule, HZ / 10)
> 
> It only stops when the device is marked inaccessible or the interface goes down.
> 
> While it runs, each pass does a usb_autopm get/put. Each pass also holds
> tp->control for 20 to 40 ms out of every 100 ms. The ethtool handlers, the MII
> ioctls and hw_phy_work all wait on that mutex.
> 
> Each pass also reaches dev_err_ratelimited(). The default ratelimit of
> 10 messages per 5 seconds still lets about 2 lines per second through, with no
> end. Does that match this statement in the commit message?
> 
>   A timeout is logged ratelimited, so a stuck busy bit does not flood
>   the log
> 
> In addition, delay_autosuspend() returns true whenever the delayed work is
> pending:
> 
>         if (work_busy(&tp->schedule.work) || sw_linking != hw_linking)
>                 return true;
> 
> rtl8153_in_nway() also returns true on a failed read. Runtime autosuspend
> would therefore be blocked for as long as the fault lasts.
> 
> The commit message leaves recovery from a TGPHY timeout to a follow-up
> series. Should this retry be bounded in the meantime?
> 
> [ ... ]
> 
> --
> Sashiko AI review ·
> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130063123.2408-1-
> nic_swsd%40realtek.com

Best Regards,
Chih-Kai
---
pw-bot: cr

  reply	other threads:[~2026-12-03  8:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  6:31 [PATCH net-next v10 00/12] r8152: refactor and extend RTL8157/8159 support Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 01/12] r8152: fix RTL8156/RTL8156B/RTL8157/RTL8159 up and down settings Chih Kai Hsu
2026-12-01  6:45   ` netdev-bot+sashiko
2026-11-30  6:31 ` [PATCH net-next v10 02/12] r8152: add rtl8157_unload() for RTL8157 and RTL8159 Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-11-30  6:31 ` [PATCH net-next v10 03/12] r8152: add rtl8157_change_mtu() " Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-11-30  6:31 ` [PATCH net-next v10 04/12] r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159 Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-11-30  6:31 ` [PATCH net-next v10 05/12] r8152: split r8156_init by generation and factor out wait_autoload_done Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 06/12] r8152: add new init writes for RTL8156/8156B/8157/8159 Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 07/12] r8152: accept PLA and USB firmware blocks for RTL8157 and RTL8159 Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 08/12] r8152: split RTL_VER_17 into QFN68 and QFN100 package variants Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-12-01 12:14     ` Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 09/12] r8152: split rtl8156_enable/up/down into per-generation functions Chih Kai Hsu
2026-11-30  6:31 ` [PATCH net-next v10 10/12] r8152: split r8157_hw_phy_cfg into RTL8157 and RTL8159 variants Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-11-30  6:31 ` [PATCH net-next v10 11/12] r8152: add TGPHY register access for RTL8157 and RTL8159 Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-12-03  8:03     ` Chih Kai Hsu [this message]
2026-11-30  6:31 ` [PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68 Chih Kai Hsu
2026-12-01  6:46   ` netdev-bot+sashiko
2026-12-01 12:21     ` Chih Kai Hsu
2026-11-30  6:35 ` [PATCH net-next v10 00/12] r8152: refactor and extend RTL8157/8159 support netdev-bot+sinfo

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=f9d3a228cccb4929bf8429c5d4018467@realtek.com \
    --to=hsu.chih.kai@realtek.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=pabeni@redhat.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