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 v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
Date: Tue, 01 Dec 2026 06:46:12 +0000 [thread overview]
Message-ID: <179610757206.3146.5510888567644843790@kernel.org> (raw)
In-Reply-To: <20261130063123.2408-13-nic_swsd@realtek.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · 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] The new power-cut recovery in r8157_ups_en(false) can never
run from r8157_init(), so a reset-resume after a UPS power cut does…
- [Medium] The driver treats RTL8157 (RTL_VER_16) backup-restore two
different ways.
- [Medium] Runtime resume has a new failure path with no recovery.
- [Medium] After a UPS power cut, r8157_ups_en(false) starts the fixed 20
ms BACKUP_RESTRORE poll and then calls hw_phy_cfg() without first…
- [Medium] r8152: PLA registers accessed before r8157_ups_en() on runtime
resume
- [Low] r8157_ups_en(false) forces the USB MAC firmware to be re-applied
by writing 0 to a hardcoded address, USB_FW_USB_VER (0xcfd7, line…
--
r8152: enable UPS for RTL8157 and RTL8159 QFN68
This patch adds r8157_ups_en() and calls it from rtl8157_runtime_enable()
for RTL_VER_16 and RTL_VER_17_QFN68, so UPS is toggled across runtime
suspend and resume. It also extends r8156_ups_flags() with per-speed EEE
flags and two new speed encodings. On the disable path, after a power cut,
it waits for backup-restore and clears USB_FW_USB_VER before the firmware
is applied again.
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index b9586c30c04dd..0fb6dfe4abf56 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
[ ... ]
> @@ -4496,6 +4534,58 @@ static void r8156_ups_en(struct r8152 *tp, bool enable)
> }
> }
>
> +static void r8157_ups_en(struct r8152 *tp, bool enable)
> +{
> + u32 ocp_data;
> + int ret;
> +
> + if (enable) {
[ ... ]
> + } else {
> + ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
> + UPS_EN | USP_PREWAKE);
> +
> + ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_MISC_2,
> + UPS_FORCE_PWR_DOWN);
> +
> + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
> + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
> + return;
> +
> + if (ocp_data & PCUT_STATUS) {
[Severity: Medium]
On resume, the PLA registers are written before UPS is disabled. Is
that ordering intended?
rtl8157_runtime_enable(false) first runs r8153_queue_wake(tp, false)
and rtl_runtime_suspend_enable(tp, false), and only then calls
r8157_ups_en(tp, false). The following are all written while UPS_EN,
USP_PREWAKE and UPS_FORCE_PWR_DOWN are still set:
PLA_INDICATE_FALG, PLA_SUSPEND_FLAG, PLA_EXTRA_STATUS, PLA_CRWECR,
PLA_CONFIG34, and PLA_CONFIG5 and PLA_CFG_WOL via __rtl_set_wol()
Those writes also happen before the BACKUP_RESTRORE poll has confirmed
that the device has recovered from a power cut.
The existing runtime paths that toggle UPS disable it first.
rtl8153b_runtime_enable() has:
} else {
r8153b_ups_en(tp, false);
r8153_queue_wake(tp, false);
rtl_runtime_suspend_enable(tp, false);
rtl8153c_runtime_enable() uses the same order. So do r8156_init() and
r8157_init(). The enable side of rtl8157_runtime_enable() already arms
UPS last, so only the resume side is inverted.
If PCUT_STATUS is set on resume, could these writes be lost? They clear
UPCOMING_RUNTIME_D3 and LINK_OFF_WAKE_EN and restore
tp->saved_wolopts. Could the backup-restore then overwrite them with
the suspend-time state, which had WAKE_ANY and LINK_OFF_WAKE_EN set?
The device could then come back from runtime resume still configured
to wake on any event and on link-off, rather than with the wolopts the
user asked for.
There is a second ordering issue. r8153_queue_wake(tp, false) clears
LINK_CHG_EVENT and LINK_CHANGE_FLAG before r8157_ups_en() reprograms
the PHY through hw_phy_cfg() and rtl8152_set_speed(). Any link-change
state raised by that PHY reset is therefore not cleared.
Should r8157_ups_en(tp, false) move to the top of the else branch, to
match rtl8153b_runtime_enable()?
[Severity: Medium]
After a UPS power cut, this starts the 20 ms BACKUP_RESTRORE poll and
then calls hw_phy_cfg() without waiting for MAC autoload first. Is that
safe?
The other post-power-cut paths in the driver do wait. r8153b_ups_en()
has:
if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
if (wait_autoload_done(tp))
return;
tp->rtl_ops.hw_phy_cfg(tp);
r8157_init() runs r8156b_wait_loading_flash(), then wait_autoload_done(),
then r8159_wait_backup_restore().
This path never calls wait_autoload_done(). r8156b_wait_loading_flash()
only runs inside hw_phy_cfg(), which is after the poll.
If autoload or flash loading is still running when runtime resume
starts, could the 20 ms poll time out and mark the device inaccessible?
Or could the PHY be reprogrammed before autoload has finished?
r8156_ups_en(false), which this function mirrors, also skips the
autoload wait. But r8156_ups_en(true) is never called anywhere, so that
path has never been exercised.
> + ret = read_poll_timeout(ocp_read_word, ocp_data,
> + test_bit(RTL8152_INACCESSIBLE,
> + &tp->flags) ||
> + (ocp_data & BACKUP_RESTRORE),
> + 200, 20000, false, tp,
> + MCU_TYPE_USB, USB_GPHY_CTRL);
[Severity: Medium]
The runtime path and the init path treat RTL8157 (RTL_VER_16)
backup-restore differently. Which one matches the hardware?
rtl8157_runtime_enable(false) sends RTL_VER_16 into this poll, and a
timeout marks the device inaccessible. r8157_init(), however, only waits
for backup-restore on RTL8159:
switch (tp->version) {
case RTL_VER_17_QFN68:
case RTL_VER_17_QFN100:
if (r8159_wait_backup_restore(tp)) {
The backup-restore enables later in r8157_init() are also programmed
only for the RTL8159 variants: 0xb99c BIT(0) for QFN68, and 0xb9a2 for
QFN68 and QFN100.
The commit message says RTL8157 needs this wait after a power cut. If
so, r8157_init() touches the PHY on RTL_VER_16 without waiting.
If RTL8157 never asserts BACKUP_RESTRORE after a UPS power cut, then
every runtime resume after a power cut on RTL_VER_16 would time out here
and leave the interface unusable until replug.
Also, the only place in the driver that sets BACKUP_RESTRORE is
rtl_ram_code_speed_up():
ocp_word_set_bits(tp, MCU_TYPE_USB, USB_GPHY_CTRL,
GPHY_PATCH_DONE | BACKUP_RESTRORE);
Suppose no PHY speed-up firmware was loaded, for example because the
firmware file is missing, and the hardware doesn't set the bit itself.
Can this poll ever succeed?
> + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
> + return;
> +
> + if (ret) {
> + rtl_set_inaccessible(tp);
> + dev_err(&tp->intf->dev,
> + "backup-restore timed out\n");
> + return;
> + }
[Severity: Medium]
If this times out during runtime resume, does anything recover the
device?
r8157_ups_en() returns void, so rtl8157_runtime_enable() carries on with
r8157_u2p3en() and r8153b_u1u2en(). rtl8152_runtime_resume() then
returns 0. rtl8152_resume() only resets the device on system resume:
if (!runtime_resume && test_bit(RTL8152_INACCESSIBLE, &tp->flags))
usb_reset_device(tp->udev);
Once RTL8152_INACCESSIBLE is set, the OCP accessors short-circuit, so
they never reach the reg_access_reset_count and usb_queue_reset_device()
recovery either. The interface stays up but unusable until replug or an
unrelated reset.
The commit message acknowledges this and leaves recovery to a follow-up
series. Could this call usb_queue_reset_device(tp->intf) instead, as the
driver already does on TX timeout?
> +
> + /* clear USB fw_ver_reg */
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);
[Severity: Low]
Is it guaranteed that the loaded firmware's USB block uses 0xcfd7 as its
version register?
rtl8152_fw_mac_apply() decides whether to skip a block using the address
from the firmware file:
fw_ver_reg = __le16_to_cpu(mac->fw_ver_reg);
if (fw_ver_reg && ocp_read_byte(tp, MCU_TYPE_USB, fw_ver_reg) >= mac->fw_ver_data) {
rtl8152_is_fw_mac_ok() doesn't check fw_ver_reg against any expected
value for RTL_VER_16/17.
Suppose an rtl8157/rtl8159 firmware image declares a different
fw_ver_reg for its RTL_FW_USB block. This write then has no effect, and
after a power cut the USB block is skipped as already newest. It would
also zero whatever register is at 0xcfd7.
Could this clear the fw_ver_reg from the loaded RTL_FW_USB block
instead, or bypass the version check after a power cut?
> +
> + tp->rtl_ops.hw_phy_cfg(tp);
> +
> + rtl8152_set_speed(tp, tp->autoneg, tp->speed,
> + tp->duplex, tp->advertising);
> + }
> + }
> +}
[ ... ]
> @@ -9148,7 +9257,7 @@ static void r8157_init(struct r8152 *tp)
> ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
>
> r8157_power_cut_en(tp, false);
> - r8156_ups_en(tp, false);
> + r8157_ups_en(tp, false);
[Severity: Medium]
Can the power-cut branch of r8157_ups_en(tp, false) ever run from
r8157_init()?
The line before it clears PCUT_STATUS:
r8157_power_cut_en()
ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);
So r8157_ups_en() always reads PCUT_STATUS as 0 here. It skips the
backup-restore poll, the USB_FW_USB_VER clear, and the hw_phy_cfg() and
rtl8152_set_speed() reprogramming.
rtl8157_runtime_enable(true) now arms UPS for RTL_VER_16 and
RTL_VER_17_QFN68. If the USB core reset-resumes the device after a UPS
power cut, for example after a failed resume, rtl8152_reset_resume()
never reaches rtl8157_runtime_enable(false):
rtl8152_reset_resume()
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
rtl_reset_ocp_base(tp);
tp->rtl_ops.init(tp);
r8157_power_cut_en(tp, false) <- clears PCUT_STATUS
r8157_ups_en(tp, false) <- skips recovery
queue_delayed_work(..., &tp->hw_phy_work, 0);
hw_phy_cfg()
rtl8152_fw_mac_apply() <- sees stale USB version
The commit message says the USB version register survives the power cut
while the USB patch is lost. Wouldn't rtl8152_fw_mac_apply() then skip
the USB block and leave the USB MCU running without its patch?
On RTL_VER_16 this init path also has no backup-restore wait, because
r8157_init() only calls r8159_wait_backup_restore() for the QFN68 and
QFN100 variants.
Should PCUT_STATUS be checked before r8157_power_cut_en(tp, false)
clears it? As written, replacing r8156_ups_en() with r8157_ups_en() here
doesn't change the power-cut handling.
> r8153_queue_wake(tp, false);
> rtl_runtime_suspend_enable(tp, false);
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130063123.2408-1-nic_swsd%40realtek.com
next prev parent reply other threads:[~2026-12-01 6:46 UTC|newest]
Thread overview: 24+ 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-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 [this message]
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=179610757206.3146.5510888567644843790@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®