All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chih Kai Hsu" <hsu.chih.kai@realtek.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
Date: Tue, 01 Dec 2026 06:32:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-242714@kernel.org> (raw)
In-Reply-To: <20261130063123.2408-13-nic_swsd@realtek.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] r8152: PCUT_STATUS cleared before r8157_ups_en(tp, false) in
  r8157_init()
- [Medium] r8152: PLA registers accessed before r8157_ups_en() on
  runtime resume
- [Medium] r8152: unrecoverable RTL8152_INACCESSIBLE latch in
  r8157_ups_en()
--

commit c10e0bfa00a1dd7f7d30bc58798ee583928fdb60
Author: Chih Kai Hsu <hsu.chih.kai@realtek.com>

r8152: enable UPS for RTL8157 and RTL8159 QFN68

This commit adds r8157_ups_en(), updates r8156_ups_flags() with per-speed
EEE and speed flags, and enables UPS on runtime suspend and resume for
RTL8157 and RTL8159 QFN68.

> 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) {
> +		r8156_ups_flags(tp);
> +
> +		ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
> +				  UPS_EN | USP_PREWAKE | PHASE2_EN);
> +
> +		ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_MISC_2,
> +				  UPS_FORCE_PWR_DOWN);
> +	} 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) {
> +			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);
> +			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]
As reported by Jakub Kicinski on v7 [1], can latching RTL8152_INACCESSIBLE
here leave the interface permanently unusable after a runtime resume?

When read_poll_timeout() times out during rtl8152_runtime_resume() ->
rtl8157_runtime_enable(tp, false) -> r8157_ups_en(tp, false), the error is
not returned to the PM core and no USB reset is queued, while
rtl8152_resume() skips its usb_reset_device() fallback when runtime_resume
is true:

drivers/net/usb/r8152.c:rtl8152_resume() {
    ...
	if (!runtime_resume && test_bit(RTL8152_INACCESSIBLE, &tp->flags))
		usb_reset_device(tp->udev);
    ...
}

Every subsequent r8152_control_msg() then returns -ENODEV before reaching
usb_queue_reset_device(), so nothing clears RTL8152_INACCESSIBLE until the
device is replugged or reset externally.

> +
> +			/* clear USB fw_ver_reg */
> +			ocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);
> +
> +			tp->rtl_ops.hw_phy_cfg(tp);
> +
> +			rtl8152_set_speed(tp, tp->autoneg, tp->speed,
> +					  tp->duplex, tp->advertising);
> +		}
> +	}
> +}
> +
>  static void r8153_power_cut_en(struct r8152 *tp, bool enable)
>  {
>  	if (enable)
> @@ -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), matching rtl8153b_runtime_enable(),
rtl8153c_runtime_enable(), and r8157_init()?

Calling r8153_queue_wake(tp, false) and rtl_runtime_suspend_enable(tp,
false) first accesses MCU_TYPE_PLA registers while UPS is still active and
before r8157_ups_en(tp, false) waits for BACKUP_RESTRORE after a power cut,
so the writes clearing UPCOMING_RUNTIME_D3 and LINK_OFF_WAKE_EN and
restoring tp->saved_wolopts can be ignored or overwritten by the restored
suspend-time snapshot.

> +
>  		r8157_u2p3en(tp, true);
>  		if (tp->udev->speed >= USB_SPEED_SUPER)
>  			r8153b_u1u2en(tp, true);
> @@ -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);
>  	r8153_queue_wake(tp, false);
>  	rtl_runtime_suspend_enable(tp, false);

[Severity: Medium]
Does r8157_power_cut_en(tp, false) clear PCUT_STATUS before
r8157_ups_en(tp, false) can check it?

drivers/net/usb/r8152.c: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);
		ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_MISC_2, BIT(1));
	}
}

Because PCUT_STATUS in USB_MISC_0 is cleared on the preceding line, the
if (ocp_data & PCUT_STATUS) block in r8157_ups_en(tp, false) is never
entered from r8157_init().  When re-initializing via r8157_init() after a
UPS power cut (such as on rtl8152_reset_resume()), RTL_VER_16 skips waiting
for BACKUP_RESTRORE, and neither RTL_VER_16 nor RTL_VER_17_QFN68 clears
USB_FW_USB_VER, causing rtl8152_fw_mac_apply() to see the surviving version
register and skip reloading the lost USB firmware patch.

[1] https://lore.kernel.org/r/20261021005214.1255071-1-kuba@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130063123.2408-1-nic_swsd@realtek.com?part=12

  reply	other threads:[~2026-12-01  6:32 UTC|newest]

Thread overview: 26+ 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:32   ` sashiko-bot [this message]
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
2026-12-01  6:32 ` sashiko-bot

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=sashiko-outbox-242714@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hsu.chih.kai@realtek.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.