From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796107573; b=vo6aJrSwANvzmTZ1VPSkLW6i8pN4Y9LrSXUCxVTHWx4J+ySnwhs0Z4P2uepxp2pTOPEK 3cH2hUjICptjSrIG+G6sylEci2MK1mWHqzQyXqY0tCFSAelUwsTeeTrmqtt1ui3MnGbx/ tT7jM29sPmgmIAkjWAVgRWo/+LM3rFRZof+vXXBNj6AXxm5dOCHX+UKvEaVg3rfYHhvGs 2Sh9HYD7sm5J4/uiXBBZ7zpLnfM0U00FTEt1ajtBgpdtFjIC2/LkklPxA9Ai33V8Hvsaa M25pvdZLP66HIDmRppEiQUgyKGamEH9aKDRDqyWxtVCuQsFKCz/BFp1tas4AurH8ZfA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796107573; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=v1Bsp7Pl3IAIk5v50WC/w9rPTxSicMIMKocFEqgo9P4=; b=SikGkGJA/TkKf6RNmw0R8ZHaXSZsQCedglIqYANggHMWFY/KaRN1g2DPAUC2elqUpPBg Dv52RC2pYXj2/fBAExkuJV5lkgxue3ahiU0AYD5HcA9Yvece3pwSKRebNsOZMwLe6sj/T o/tp+GCbBRbaREpzaMRY96+OVnfzVorrifuBZ9fnWU9vlepQaJ1zgYV9ERhTCI5WmUxwL Bl0SZdX+jicJHSRAXpQBfM/4N7h3h3Ty1oDOmgRWP+uKmS2OAytxt/iEnlB4qY5BgOZ4k 4wALbwUJgtVx5HlaVa9wkTk3q9Lke/+6+i9d9oIwuHKrbLxNe5dZnTR+3RkJsSWl8GQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mHtovUH3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95EAC606A697; Tue, 1 Dec 2026 06:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mHtovUH3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 800421F00A23; Tue, 1 Dec 2026 06:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796107573; bh=v1Bsp7Pl3IAIk5v50WC/w9rPTxSicMIMKocFEqgo9P4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=mHtovUH35+yy8BUdFmHWnvIQt/8JKL+PWcosho1HXDY4QbEpYT1DpbrDjFHNHFwV5 nIxSa3hu4eQJkTerTQsGEmcRohqRfA9n4T29rsTBPgyE8rh7Otput+wqqiOnLK7kDb QLxvNe5+ku6D60W+nrM4wbxRGSlr826PAq6LyUDotwNs7+2LfUQayOguObVA0Znadr KS//hft3WwkpiqV8nl98QTBPnCFIgGW2p438auVIpT6IugXjd6oMuX4VqHn3YEShH1 aYxfly6z+H++Yw+m0Eyupz+NDdYVMlzBoPg/FO9yNHRDBklqyg4ng4E8mGG2UCSp6B gw3EEOVrpjUGw== Subject: Re: [PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68 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 Date: Tue, 01 Dec 2026 06:46:12 +0000 Message-ID: <179610757206.3146.5510888567644843790@kernel.org> In-Reply-To: <20261130063123.2408-13-nic_swsd@realtek.com> References: <20261130063123.2408-13-nic_swsd@realtek.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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