> 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…%40realtek.com
Best Regards, Chih-Kai --- pw-bot: cr