From: netdev-bot+sashiko@kernel.org
To: hsu.chih.kai@realtek.com
Cc: davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
nic_swsd@realtek.com, linux-kernel@vger.kernel.org,
linux-usb@vger.kernel.org, edumazet@google.com, bjorn@mork.no,
pabeni@redhat.com, andrew+netdev@lunn.ch, mail@birger-koblitz.de
Subject: Re: [PATCH net-next v9 11/12] r8152: add TGPHY register access for RTL8157 and RTL8159
Date: Fri, 27 Nov 2026 04:27:07 +0000 [thread overview]
Message-ID: <179575362702.3135.11502039200918587671@kernel.org> (raw)
In-Reply-To: <20261126033211.51850-12-nic_swsd@realtek.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 5
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] set_carrier() now returns early when the BMSR read fails, and
the link-change event is lost.
- [Low] rtl_tgphy_access() reports a write as successful once the command
has been posted.
- [Low] Two statements in the commit message are not quite right.
- [Low] read_mii_word() now returns 0 for a failed PHY read, and the MII
library callers in drivers/net/mii.c take that 0 as real register…
- [Low] rtl_tgphy_access() relies on the comment 'A failed control
transfer latches RTL8152_INACCESSIBLE' and ignores the return values…
- [Low] After writing BMCR_RESET, rtl8152_set_speed() polls BMCR for up
to 50 x 20 ms, but the new loop stops on the first failed read: `if…
--
r8152: add TGPHY register access for RTL8157 and RTL8159
This patch adds a TGPHY command channel for PHY register access on
RTL8157/RTL8159 and routes ocp_reg_read()/ocp_reg_write() through new
per-chip rtl_ops.phy_read/phy_write hooks. The PHY accessors and helpers
now return int, and a number of callers are changed to act on a failed
access.
> - read_mii_word() reports a failed read as 0, because the MII library
> takes the return value for register content. A TGPHY timeout
> returned as an errno would look like a BMCR with autonegotiation
> enabled, and mii_nway_restart() would write it back; with 0 it
> returns without writing. -ENODEV for an inaccessible device is
> still returned, as the writes that follow are blocked then.
[ ... ]
> Older chips are unaffected, as r8152_phy_read() always succeeds.
[Severity: Low]
Is this last statement accurate? A few paths also change on the OCP-path
chips.
In r8156_hw_phy_cfg() for RTL_VER_11, the 0xd068 PHY read now always runs,
and it runs before the MID_REVERSE test. Before, it only ran when
MID_REVERSE was set:
ocp_reg_read(tp, 0xd068, &data);
if ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) & MID_REVERSE) &&
(data & BIT(1))) {
rtl8152_set_pauseparam() now reads BMCR even when pause->autoneg is 0.
rtl_pre_ram_code() now returns the errno from rtl_phy_patch_request()
instead of always returning -ETIME. rtl_phy_patch_request() now also tries
a release on the -ENODEV path.
None of these look harmful. Should the commit message mention them?
In the read_mii_word() bullet, -ENODEV is only still returned by the
test_bit(RTL8152_INACCESSIBLE) check at entry. If the device becomes
inaccessible during the access, r8152_mdio_read() returns -ENODEV and
read_mii_word() turns it into 0:
return ret < 0 ? 0 : ret;
Could the wording be changed to match the code?
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 2f3d97e2400c3..e6a5d35403a28 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
[ ... ]
> @@ -1822,7 +1866,10 @@ static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
>
> ret = r8152_mdio_read(tp, reg);
>
> - return ret;
> + /* The MII library takes the return value for register content,
> + * so a failed read must not be passed on as an errno.
> + */
> + return ret < 0 ? 0 : ret;
> }
[Severity: Low]
With a failed read reported as 0, the MII library callers in
drivers/net/mii.c treat it as real register content.
mii_nway_restart() sees BMCR_ANENABLE clear and returns -EINVAL. On
RTL8157/RTL8159, a TGPHY timeout on that BMCR read therefore reaches
userspace as -EINVAL from rtl8152_nway_reset() (ethtool -r). The same
happens in rtl_ethtool_set_eee(), after eee_set() has already written the
EEE registers.
mii_ethtool_get_link_ksettings() returns void. With BMCR=0 it reports
AUTONEG_DISABLE with SPEED_10/DUPLEX_HALF, and BMSR=0 gives SPEED_UNKNOWN.
It also overwrites mii->full_duplex.
In rtl8152_get_link_ksettings(), the new OCP_10GBT_CTRL/STAT reads
propagate the error. If only the MII library reads fail, though, the
function returns 0 with made-up link settings. Is this split intended?
The commit message explains the 0 mapping for mii_nway_restart(). It does
not mention the misleading -EINVAL or the get_link_ksettings output.
[ ... ]
> +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;
> +
> + if (write) {
> + cmd |= TGPHY_CMD_WR;
> + ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);
> + }
>
> - return data & clear;
> + ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);
> +
> + cmd |= TGPHY_CMD_BUSY;
> + ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);
> +
> + if (!write) {
> + ret = wait_tgphy_cmd_ready(tp);
> + if (ret < 0)
> + goto out;
> +
> + *data = ocp_read_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA);
> + }
[Severity: Low]
For a write, the only busy wait happens before the command is issued. Once
DATA/ADDR/CMD have been posted, ret is still 0. If the busy bit never
clears for that write, the function still returns 0. The -ETIMEDOUT is then
reported by whichever TGPHY access comes next.
The commit message says rtl8152_set_speed() updates the cached
speed/duplex state only once the final BMCR write succeeds. When
PHY_RESET is not pending, nothing reads the PHY after that write. So
tp->ups_info.speed_duplex, tp->mii.full_duplex and tp->mii.force_media
are committed even if the PHY never took the write. SIOCSMIIREG in
rtl8152_ioctl() now also returns this status to userspace.
ocp_adv_write() uses the same posted-write pattern, so this may be the
intended hardware protocol.
Should the write path wait for TGPHY_CMD_BUSY to clear after posting the
command? If not, should it be documented that write success only means
the command was issued?
> +
> +out:
> + /* A failed control transfer latches RTL8152_INACCESSIBLE */
> + if (!ret && test_bit(RTL8152_INACCESSIBLE, &tp->flags))
> + ret = -ENODEV;
> +
> + return ret;
> +}
[Severity: Low]
Is this comment true for every failed transfer? r8152_control_msg() returns
-ENODEV early, without setting the flag:
if (ret == -ENODEV)
return ret;
generic_ocp_read() and generic_ocp_write() then call rtl_set_unplug(). That
function only latches the flag once the USB core has marked the device
detached:
static void rtl_set_unplug(struct r8152 *tp)
{
if (tp->udev->state == USB_STATE_NOTATTACHED)
rtl_set_inaccessible(tp);
}
get_registers()/set_registers() can also return -ENOMEM on an allocation
failure without touching the flag.
In these cases a DATA/ADDR/CMD write can be dropped, or the final
USB_TGPHY_DATA read can return 0xffff. For -ENOMEM it can return an
uninitialised value from the local tmp in ocp_read_word(). Either way,
rtl_tgphy_access() still returns 0.
This is no worse than the OCP path. Still, do the comment and the commit
message ("returns an errno (-ENODEV if the device is inaccessible)")
overstate what is detected here?
[ ... ]
> if (bmcr & BMCR_RESET) {
> int i;
>
> for (i = 0; i < 50; i++) {
> msleep(20);
> - if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0)
> + ret = r8152_mdio_read(tp, MII_BMCR);
> + if (ret < 0 || !(ret & BMCR_RESET))
> break;
> }
> +
> + /* The new settings are already applied and cached. */
> + ret = 0;
> }
[Severity: Low]
Does a single failed read here end the reset wait early? On
RTL8157/RTL8159, a TGPHY -ETIMEDOUT breaks out of the loop as if
BMCR_RESET had cleared, and ret is then forced to 0. Callers such as
rtl_hw_phy_work_func_t() then continue PHY setup while the PHY may still
be in reset.
r8153_phy_status() in this patch treats a failed read as not ready and
keeps polling. Would it be more consistent to stop here only on -ENODEV,
and keep polling on a timeout?
The commit message says a failed read is not reported. It does not say
that the read also ends the wait.
[ ... ]
> @@ -7240,8 +7480,13 @@ static void set_carrier(struct r8152 *tp)
> {
> struct net_device *netdev = tp->netdev;
> struct napi_struct *napi = &tp->napi;
> + int bmsr;
>
> - if (r8152_mdio_read(tp, MII_BMSR) & BMSR_LSTATUS) {
> + bmsr = r8152_mdio_read(tp, MII_BMSR);
> + if (bmsr < 0)
> + return;
> +
[Severity: Medium]
Can this lose the link change event? rtl_work_func_t() has already
consumed the flag before it calls set_carrier():
if (test_and_clear_bit(RTL8152_LINK_CHG, &tp->flags))
set_carrier(tp);
On a link down, intr_callback() has also already stopped the queue:
if (netif_carrier_ok(tp->netdev)) {
netif_stop_queue(tp->netdev);
set_bit(RTL8152_LINK_CHG, &tp->flags);
schedule_delayed_work(&tp->schedule, 0);
}
Suppose the BMSR read then times out on RTL8157/RTL8159 in
rtl_tgphy_access(). Neither the netif_carrier_off() path nor
netif_wake_queue() runs, and RTL8152_LINK_CHG is not set again.
The netdev then keeps the carrier on with the TX queue stopped. This lasts
until another interrupt shows a mismatch, or until the TX watchdog calls
rtl8152_tx_timeout(). A link up can be missed the same way.
Could this error path set RTL8152_LINK_CHG again and reschedule
tp->schedule? The LINK_STATUS branch at the end of set_carrier() already
does that.
> if (bmsr & BMSR_LSTATUS) {
> if (!netif_carrier_ok(netdev)) {
> tp->rtl_ops.enable(tp);
> netif_stop_queue(netdev);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126033211.51850-1-nic_swsd%40realtek.com
next prev parent reply other threads:[~2026-11-27 4:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 3:31 [PATCH net-next v9 00/12] r8152: refactor and extend RTL8157/8159 support Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 01/12] r8152: fix RTL8156/RTL8156B/RTL8157/RTL8159 up and down settings Chih Kai Hsu
2026-11-27 4:26 ` netdev-bot+sashiko
2026-11-26 3:32 ` [PATCH net-next v9 02/12] r8152: add rtl8157_unload() for RTL8157 and RTL8159 Chih Kai Hsu
2026-11-27 4:27 ` netdev-bot+sashiko
2026-11-26 3:32 ` [PATCH net-next v9 03/12] r8152: add rtl8157_change_mtu() " Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 04/12] r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159 Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 05/12] r8152: split r8156_init by generation and factor out wait_autoload_done Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 06/12] r8152: add new init writes for RTL8156/8156B/8157/8159 Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 07/12] r8152: accept PLA and USB firmware blocks for RTL8157 and RTL8159 Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 08/12] r8152: split RTL_VER_17 into QFN68 and QFN100 package variants Chih Kai Hsu
2026-11-27 4:27 ` netdev-bot+sashiko
2026-11-27 8:36 ` Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 09/12] r8152: split rtl8156_enable/up/down into per-generation functions Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 10/12] r8152: split r8157_hw_phy_cfg into RTL8157 and RTL8159 variants Chih Kai Hsu
2026-11-27 4:27 ` netdev-bot+sashiko
2026-11-26 3:32 ` [PATCH net-next v9 11/12] r8152: add TGPHY register access for RTL8157 and RTL8159 Chih Kai Hsu
2026-11-27 4:27 ` netdev-bot+sashiko [this message]
2026-11-27 8:38 ` Chih Kai Hsu
2026-11-26 3:32 ` [PATCH net-next v9 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68 Chih Kai Hsu
2026-11-27 4:27 ` netdev-bot+sashiko
2026-11-27 8:47 ` Chih Kai Hsu
2026-11-26 3:38 ` [PATCH net-next v9 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=179575362702.3135.11502039200918587671@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bjorn@mork.no \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hsu.chih.kai@realtek.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mail@birger-koblitz.de \
--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
all inboxes | Powered by JetHome®