The Linux Kernel Mailing List
 help / color / mirror / Atom feed
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 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
Date: Fri, 27 Nov 2026 04:27:08 +0000	[thread overview]
Message-ID: <179575362872.3135.13750134827744924727@kernel.org> (raw)
In-Reply-To: <20261126033211.51850-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] On RTL8157 (RTL_VER_16), the probe/reset_resume path and the
  new runtime-resume path disagree about the backup-restore wait after a…
- [Medium] r8157_ups_en(tp, false) adds a permanent failure mode to
  runtime resume.
- [Medium] In the new runtime-resume path of rtl8157_runtime_enable(tp,
  false), r8157_ups_en(tp, false) runs only after r8153_queue_wake(tp,…
- [Medium] r8157_ups_en(tp, false) polls USB_GPHY_CTRL.BACKUP_RESTRORE
  with a 20 ms timeout after every power cut, for every chip it is…
- [Medium] When PCUT_STATUS is set, the power-cut recovery branch of the
  new r8157_ups_en(tp, false) waits for BACKUP_RESTRORE, clears…
- [Low] To force the USB MCU firmware to be re-applied after a power cut,
  r8157_ups_en(tp, false) writes 0 to a hard-coded register,…

--

r8152: enable UPS for RTL8157 and RTL8159 QFN68

This patch adds r8157_ups_en() and calls it from rtl8157_runtime_enable(),
so RTL8157 and RTL8159 QFN68 enter and exit UPS across runtime suspend and
resume. It also extends r8156_ups_flags() with per-speed EEE flags and
5G/10G speed encodings for these chips. On the UPS disable path the driver
waits for backup-restore after a power cut, then applies the PHY
configuration again.

> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index e6a5d35403a28..e294e52b426b5 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)
> +{

[ ... ]

> +		if (ocp_data & PCUT_STATUS) {
> +			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]
Does RTL8157 (RTL_VER_16) set BACKUP_RESTRORE by itself after a
power cut?

r8157_init() only waits for it on the RTL8159 variants:

r8157_init() {
    ...
	switch (tp->version) {
	case RTL_VER_17_QFN68:
	case RTL_VER_17_QFN100:
		if (r8159_wait_backup_restore(tp)) {
    ...
}

The only other user of BACKUP_RESTRORE in the driver is
rtl8152_fw_phy_nc_apply(), where software sets the bit itself.

Suppose RTL8157 never asserts the bit. Every runtime resume after a UPS
power cut on RTL_VER_16 would then time out here after 20 ms and mark the
device inaccessible. hw_phy_cfg() and rtl8152_set_speed() would be
skipped, and the r8157_u2p3en(true) and r8153b_u1u2en(true) writes after
it would be dropped. Is that what happens?

The commit message says the wait applies "on RTL8157 as well as RTL8159",
but r8157_init() treats RTL8157 as not needing it. Which one is correct
for this chip?

> +			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]
Can this leave the NIC permanently unusable after a runtime resume?

The call chain is:

rtl8152_resume()->rtl8152_runtime_resume()->
    tp->rtl_ops.autosuspend_en(tp, false)->rtl8157_runtime_enable()->
        r8157_ups_en(tp, false)

r8157_ups_en() returns void, and rtl8152_runtime_resume() returns 0 in
every case.

rtl8152_resume() skips its existing inaccessible recovery for runtime
resume:

	if (!runtime_resume && test_bit(RTL8152_INACCESSIBLE, &tp->flags))
		usb_reset_device(tp->udev);

After the timeout, every generic_ocp_read() and generic_ocp_write()
returns -ENODEV. The interface then stays unusable until a replug.

The commit message acknowledges this and leaves recovery to a follow-up
series. Runtime resume runs far more often than probe or reset_resume, and
before this patch rtl8157_runtime_enable(false) could not fail this way.
Could this path call usb_queue_reset_device(), as rtl8152_tx_timeout() and
the control message error path already do?

> +
> +			/* clear USB fw_ver_reg */
> +			ocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);

[Severity: Low]
rtl8152_fw_mac_apply() does not look at USB_FW_USB_VER when deciding
whether to skip a block. It uses the register named in the firmware blob:

	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) {

Nothing in the driver links 0xcfd7 to the USB block's fw_ver_reg. If a
current or future rtl8157/rtl8159 blob names a different register, would
the USB MCU patch be skipped after the power cut?

This code also leaves the PLA block's version register alone. If the power
cut drops the PLA patch, would that patch be applied again?

Could this use the fw_ver_reg values from tp->rtl_fw rather than a
hard-coded register?

> +
> +			tp->rtl_ops.hw_phy_cfg(tp);

[Severity: Medium]
Is a wait_autoload_done() call needed before hw_phy_cfg() here?

The other runtime UPS implementations wait for autoload in the same power
cut branch. For example, r8153b_ups_en():

		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() also runs r8156b_wait_loading_flash(), then
wait_autoload_done(), then the backup-restore wait, all before PHY setup.

Before applying firmware and PHY parameters, r8157_hw_phy_cfg() only calls
r8156b_wait_loading_flash(). So this path checks backup-restore first and
flash loading second, the reverse of the init order.

r8156_ups_en(), which this function mirrors, also lacks the wait. But
r8156_ups_en(tp, true) has no caller, so its power cut branch has never
run at runtime.

If autoload is still running after the power cut, could it overwrite the
PHY parameters or MAC firmware that hw_phy_cfg() writes?

> +
> +			rtl8152_set_speed(tp, tp->autoneg, tp->speed,
> +					  tp->duplex, tp->advertising);
> +		}
> +	}
> +}

[ ... ]

> @@ -4654,9 +4744,28 @@ static void rtl8157_runtime_enable(struct r8152 *tp, bool enable)
>  		r8153b_u1u2en(tp, false);
>  		r8157_u2p3en(tp, false);
>  		rtl_runtime_suspend_enable(tp, true);
> +
> +		switch (tp->version) {
> +		case RTL_VER_16:
> +		case RTL_VER_17_QFN68:
> +			r8157_ups_en(tp, true);
> +			break;
> +		default:
> +			break;
> +		}
>  	} else {
>  		r8153_queue_wake(tp, false);
>  		rtl_runtime_suspend_enable(tp, false);
> +
> +		switch (tp->version) {
> +		case RTL_VER_16:
> +		case RTL_VER_17_QFN68:
> +			r8157_ups_en(tp, false);
> +			break;
> +		default:
> +			break;
> +		}

[Severity: Medium]
Should r8157_ups_en(tp, false) run before r8153_queue_wake(tp, false) and
rtl_runtime_suspend_enable(tp, false)?

As written, the PLA wake and WOL registers are written again before UPS
is exited and before the backup-restore wait. These are
PLA_INDICATE_FALG, PLA_SUSPEND_FLAG, PLA_EXTRA_STATUS, PLA_CRWECR and
PLA_CONFIG34.

The other chips with runtime UPS use the opposite order. For example,
rtl8153b_runtime_enable():

	} else {
		r8153b_ups_en(tp, false);
		r8153_queue_wake(tp, false);
		rtl_runtime_suspend_enable(tp, false);

The restore after a power cut could still be running when saved_wolopts
is restored and LINK_OFF_WAKE_EN and UPCOMING_RUNTIME_D3 are cleared.
Could it then bring back the suspend-time wake configuration?

There is also a second ordering change. hw_phy_cfg() and
rtl8152_set_speed() now run after LINK_CHG_EVENT and LINK_CHANGE_FLAG
have been cleared, which the 8153b/8153c sequence does not do.

> +
>  		r8157_u2p3en(tp, true);
>  		if (tp->udev->speed >= USB_SPEED_SUPER)
>  			r8153b_u1u2en(tp, true);

[ ... ]

> @@ -9141,7 +9250,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 PCUT_STATUS branch of r8157_ups_en() ever run from here?

r8157_power_cut_en(tp, false) clears the flag just before the call:

r8157_power_cut_en() {
    ...
	} else {
		ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_POWER_CUT, PWR_EN);
		ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);
    ...
}

As a result, the init path never runs the backup-restore wait, the
USB_FW_USB_VER clear or the PHY reconfiguration.

This matters more now that RTL_VER_16 can be power cut at runtime. On a
reset_resume after a runtime UPS power cut, rtl8152_reset_resume() goes
through ops->init rather than autosuspend_en(false):

	clear_bit(SELECTIVE_SUSPEND, &tp->flags);
	rtl_reset_ocp_base(tp);
	tp->rtl_ops.init(tp);
	queue_delayed_work(system_dfl_long_wq, &tp->hw_phy_work, 0);

r8157_init() only waits for backup-restore on RTL_VER_17_QFN68 and
RTL_VER_17_QFN100, so RTL_VER_16 takes the default case. After that,
r8157_hw_phy_cfg() from hw_phy_work only waits for flash loading.

Would RTL8157 then start PHY setup without waiting for backup-restore? On
this path USB_FW_USB_VER is also never cleared, for either chip.

So either the RTL8157 wait in r8157_ups_en() is not needed, or
r8157_init() is missing it for the state this patch creates. Which one is
intended?

Separately, the poll in r8157_ups_en() duplicates
r8159_wait_backup_restore(), with the same register, bit and 200 us /
20 ms timing. Could it call the helper instead, so the two sites stay in
sync?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126033211.51850-1-nic_swsd%40realtek.com

  reply	other threads:[~2026-11-27  4:27 UTC|newest]

Thread overview: 20+ 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-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
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 [this message]
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=179575362872.3135.13750134827744924727@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