🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
8 messages
8 total messages Started by Chih Kai Hsu Mon, 30 Nov 2026 06:31
[PATCH net-next v10 00/12] r8152: refactor and extend RTL8157/8159 support
#24439
Author: Chih Kai Hsu
Date: Mon, 30 Nov 2026 06:31
309 lines
22591 bytes
RTL8157 and RTL8159 have different init, enable, up/down, hw_phy_cfg,
and PHY access sequences from RTL8156. This series first fixes the
up/down, unload, change_mtu and flow control settings that these chips
shared with RTL8156 but need to be different, then separates the shared
callbacks by chip generation and adds the missing RTL8157/RTL8159
functionality: TGPHY register access via phy_read/phy_write pointers in
struct rtl_ops, and UPS support via r8157_ups_en().

v10:
- Patch #8:
  - Reword the commit message: an unknown package or a failed read of
    the package register yields RTL_VER_UNKNOWN, which rtl8152_probe()
    and the configuration selector reject with -ENODEV, so a chip whose
    package cannot be identified no longer binds to r8152.  Explain why
    skipping only the firmware is not enough, and that the package
    register is read independently by the configuration selector,
    rtl8152_probe() and r8153_ecm_probe().
  - Log an unknown package with dev_err() instead of dev_info(), as the
    device is rejected.

- Patch #10: fix the indentation of EN_ALDPS_PLLOFF.

- Patch #11:
  - Document in the commit message that a TGPHY access returns -ENODEV
    only when the device is marked inaccessible, so a failure that does
    not mark it (-ENOMEM, an unplug not yet reported by the USB core)
    is not detected, as in the OCP accessors.
  - Document that a TGPHY write only waits for the busy bit before it
    posts the command, so success means the command was issued.
  - Document the effect of read_mii_word() returning 0 on a failed read
    on mii_nway_restart(), rtl_ethtool_set_eee() and
    mii_ethtool_get_link_ksettings(), and that -ENODEV is returned only
    when the device is already inaccessible on entry.
  - Document the control-flow changes on the older chips: the 0xd068
    read in r8156_hw_phy_cfg(), the BMCR read in
    rtl8152_set_pauseparam(), and the errno of rtl_pre_ram_code() and
    the PATCH_REQUEST release in rtl_phy_patch_request().
  - In rtl8152_set_speed(), keep waiting for BMCR_RESET to clear when a
    read fails, as r8153_phy_status() does, and stop early only when the
    device is inaccessible.
  - set_carrier() sets RTL8152_LINK_CHG again and retries after 100 ms
    when the BMSR read fails, so that a link change is not lost.  The
    retry is skipped when the device is inaccessible.
  - Remove inline from r8152_mdio_write().

- Patch #12:
  - Explain in the commit message why USB_FW_USB_VER is cleared in the
    r8157_ups_en() disable path: a power cut clears the PLA firmware
    version but not the USB one, while the USB patch is lost.
  - Fix the indentation of USB_FW_USB_VER.

v9:
- Patch #4 (was v8 #4):
  - Explain in the commit message why SLOT_EN in PLA_RCR is cleared.
  - With no rate bit set, i.e. link down or a rate the driver does not
    advertise (500 or 1250 Mbit/s), disable the pause limit quietly
    with dev_dbg() instead of logging an error.
  - Update the commit message.

- Patch #6 (was v8 #6): explain in the commit message that RMT_WAKE_EN
  is managed by the firmware, and that the driver only clears a stale
  value.

- Patch #7 (new): accept the PLA and USB firmware blocks for RTL8157
  and RTL8159 in rtl8152_is_fw_mac_ok(), which rejected the whole image
  for these chips. Add a Fixes tag.

- Patch #8 (was v8 #7):
  - Select rtl8159-2.fw for QFN100 and keep rtl8159-1.fw for QFN68.
  - A failed read of the package register is logged and yields
    RTL_VER_UNKNOWN, since guessing a package could load the wrong
    firmware. __rtl_get_pkg_det() returns an errno.
  - Split the VER_17 cases added by patch #7 into QFN68 and QFN100.

- Patch #11 (was v8 #10):
  - rtl8152_set_speed() updates the cached speed/duplex, the UPS
    speed/duplex and force_media only once the final BMCR write
    succeeds, and keeps a pending PHY reset if that write fails.
    A failed read while waiting for the PHY reset to finish is
    not reported.
  - set_carrier() keeps the current link state when the BMSR read
    fails.
  - rtl8153_in_nway() reports the PHY as negotiating when the read
    fails, so that runtime suspend is delayed.
  - Update the commit message.

- Patch #12 (was v8 #11): explain in the commit message that the
  backup-restore wait in r8157_ups_en() also applies to RTL8157.

v8:
- Move the fixes to the front of the series, so that they can be
  backported without the refactoring, and add Fixes tags:
  - Patch #1 (was v7 #5): fix up and down register settings, now
    applied to the shared rtl8156_up()/rtl8156_down() before they are
    split.
  - Patch #2 and #3 (were v7 #7): split rtl8157_unload() and
    rtl8157_change_mtu() into separate patches. Reword the commit
    messages.
  - Patch #4 (was v7 #9): fix flow control for
    RTL8156/RTL8156B/RTL8157/RTL8159. It is now applied to the shared
    rtl8156_init() and rtl8156_enable(), and goes ahead of the
    refactoring. Rework the commit message: describe what was missing
    on each chip, and note that the 500 and 1250 Mbit/s rates the
    hardware can report disarm the pause limit.

- Patch #5 (was v7 #1): the RTL8156B-only part of r8156_init() is now
  the AUTO_SPEEDUP clear, as the flow control setup moved to patch #4.
  Update the commit message.

- Patch #6 (was v7 #2): RTL_VER_12 no longer gets
  r8156b_u2phy_backup().

- Patch #7 (was v7 #3): rebase on the new order, with the VER_17 cases
  in rtl_fc_pause_pkt_en(), rtl8156_up() and rtl8156_down() split into
  QFN68 and QFN100.

- Patch #8 (was v7 #4): rebase on the new order. The register fixes
  and rtl8157_change_mtu() now come from patches #1 to #3, so this
  patch is a pure split with no functional change intended. Add
  rtl8156b_enable() for RTL8156B (VER_12/13/15), so that
  rtl8156_enable() serves RTL8156 only and neither needs version
  checks.

- Patch #9 (was v7 #6): rebase on the new order.

- Patch #10 (was v7 #8):
  - Log a TGPHY busy timeout ratelimited, so that a stuck busy bit does
    not flood the log.
  - Propagate the PHY access failure also in
    rtl8152_get_link_ksettings(), r8153_get_eee() and
    r8152_mdio_read(), and stop on a failed read in rtl8153_in_nway(),
    r8156_mdio_force_mode(), r8156_eee_en() and rtl8152_fw_phy_fixup().
  - rtl8152_get_pauseparam() reports no flow control, and
    r8153_phy_status() keeps polling, when a read fails.
  - rtl8152_set_speed() leaves the cached advertising and a pending PHY
    reset untouched when a write fails.
  - read_mii_word() reports a failed read as 0, as the MII library
    takes the return value for register content.
  - rtl_phy_patch_request() returns the errno of a failed write and
    releases PATCH_REQUEST when a later step fails.
  - Rewrite the commit message and list what is left to a follow-up
    series.

- Patch #11 (was v7 #10): in r8157_ups_en(), stop waiting for the
  backup restore, and return, as soon as the device is marked
  RTL8152_INACCESSIBLE.

v7:
- Patch #1: split r8156_init() by chip generation rather than per
  chip. RTL8156 and RTL8156B share r8156_init(), and RTL8157 and
  RTL8159 share r8157_init(), since their sequences are near-identical.
  The few differences are selected with switch (tp->version).
  r8156b_init() and r8159_init() are gone.

- Patch #2: apply the new init writes to the merged r8156_init() and
  r8157_init().

- Patch #3:
  - The RTL8159 QFN68/QFN100 differences become cases of the version
    switches in r8157_init(), and the QFN68-only u2phy backup restore
    write falls through to the common u3phy backup write.
  - Report the number of retries (i - 1) in the "Needed %d retries to
    read package" warning.
  - Update the commit message.

- Patch #4:
  - Share the exit-OOB and enter-OOB sequences of RTL8156, RTL8156B,
    RTL8157 and RTL8159 through r8156_exit_oob() and r8156_enter_oob(),
    as RTL8152B and RTL8153 do.
  - Serve RTL8156 and RTL8156B (VER_10/11/12/13/15) with a single
    rtl8156_enable() instead of adding rtl8156b_enable(). The
    r8156_fc_parameter() call stays behind a version check, so it is
    no longer dropped.
  - Retitle and update the commit message.

- Patch #5: adapt to the shared r8156_exit_oob() and r8156_enter_oob().
  Update the commit message.

- Patch #7: r8156_exit_oob() now calls tp->rtl_ops.change_mtu() instead
  of rtl8156_change_mtu(), so that rtl8157_up() gets
  rtl8157_change_mtu(). Update the commit message.

- Patch #9: apply rtl_fc_pause_pkt_en() in the merged r8156_init().
  AUTO_SPEEDUP is still cleared there for RTL8156B only. Update the
  commit message.

- Patch #10: replace r8156_ups_en() with r8157_ups_en() in the merged
  r8157_init() only. Update the commit message.

v6:
- Patch #1: make it a pure split of r8156_init() per chip, plus the
  wait_autoload_done() helper, with no functional change. The new
  init writes it used to carry move to patch #2. Also convert
  r8152b_init() to wait_autoload_done().

- Patch #2 (new): add the new init writes for RTL8156B/8157/8159,
  taken out of patch #1.

- Patch #3:
  - Fix the "Needed %d retries" warning in __rtl_get_pkg_det() to
    trigger only when a retry was actually needed (i != 1).
  - Reword the commit message.

- Patch #6:
  - r8159_hw_phy_cfg() ends with rtl_eee_enable(tp, tp->eee_en) so
    that the configured state is applied in both directions.
  - Reword the commit message.

- Patch #8:
  - A TGPHY busy timeout no longer sets RTL8152_INACCESSIBLE.
    wait_tgphy_cmd_ready() logs and returns the poll error, as the
    ADV command channel does, and returns -ENODEV only if the device
    is already marked inaccessible.
  - Drop the RTL8152_INACCESSIBLE exceptions from the LAN_ON
    WARN_ON_ONCE() checks in hw_phy_cfg, which are no longer needed.
  - Narrow the commit message to what the patch does and list what is
    left to a follow-up series: the remaining callers, the MII library
    callbacks, and the recovery from a TGPHY timeout.

- Patch #9:
  - Explain the symptom, that RTL8157/RTL8159 could keep sending pause
    frames indefinitely, and add Fixes tags for RTL8156, RTL8157 and
    RTL8159.
  - Keep the FC patch in r8156b_init() split from the AUTO_SPEEDUP
    clearing, and call rtl_fc_pause_pkt_en() right before it.

- Patch #10: note in the commit message that a backup-restore timeout
  in r8157_ups_en() follows what r8159_init() does for the same wait
  (mark the device inaccessible and log, without queuing a reset), and
  that recovery is left to a follow-up series.

v5:
- Patch #1: in r8157_init()/r8159_init(), call
  r8156b_wait_loading_flash() before wait_autoload_done(). Document
  in the commit message that the "Bulk In End" bit is cleared in
  r8157_init(), and drop the claim about the FC-timer block.

- Patch #2: accept the package read only if the full word was returned,
  warn when a retry was needed, and print an unknown package as
  0x%04x. Say "firmware" instead of "PHY tuning" in the commit
  message.

- Patch #3: make it a pure split with no functional change. Its
  register fixes move to the new patch #4.

- Patch #4 (new): fix up and down register settings for
  RTL8156/8156B/8157/8159.

- Patch #5: document the new RTL8159 PHY tuning parameters in the
  commit message.

- Patch #6: add Fixes tags.

- Patch #7:
  - A TGPHY busy timeout now sets RTL8152_INACCESSIBLE and returns
    -ENODEV.
  - sram_write() returns the data-write result.
  - The PHY firmware version checks, the BMCR reset poll,
    rtl8152_set_speed(), the pause parameters and the PHY patch
    handshake handle PHY access failures.
  - SIOCGMIIREG returns 0 with val_out set on success, or the error.
  - Commit message rewritten.

- Patch #8: drop the "no link" case, since the caller checks the link.
  An unknown speed now disarms the pause limit. Commit message
  rewritten.

- Patch #9: wait for the backup-restore flag with a timeout in
  r8157_ups_en(). Rename USB_FW_USE_VER to USB_FW_USB_VER.

v4:
- Patch #1: make wait_autoload_done() bail out immediately on
  RTL8152_INACCESSIBLE instead of waiting out the full 10 second
  timeout.
- Patch #6: propagate PHY access failures instead of ignoring them.
  ocp_reg_read()/ocp_reg_write() and every helper built on top of them
  (sram_read/write, sram2_read/write, the ocp_reg_*_bits and MDIO bit
  helpers) now return int and stop silently operating on stale data
  when a TGPHY access times out.

v3:
Rebase on top of latest net-next to resolve merge conflicts.

v2:
- For patch #1, use read_poll_timeout() to replace the manual
  for-loop polling.
- For patch #2 and #3, rewrite the commit message.

Chih Kai Hsu (12):
  r8152: fix RTL8156/RTL8156B/RTL8157/RTL8159 up and down settings
  r8152: add rtl8157_unload() for RTL8157 and RTL8159
  r8152: add rtl8157_change_mtu() for RTL8157 and RTL8159
  r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159
  r8152: split r8156_init by generation and factor out
    wait_autoload_done
  r8152: add new init writes for RTL8156/8156B/8157/8159
  r8152: accept PLA and USB firmware blocks for RTL8157 and RTL8159
  r8152: split RTL_VER_17 into QFN68 and QFN100 package variants
  r8152: split rtl8156_enable/up/down into per-generation functions
  r8152: split r8157_hw_phy_cfg into RTL8157 and RTL8159 variants
  r8152: add TGPHY register access for RTL8157 and RTL8159
  r8152: enable UPS for RTL8157 and RTL8159 QFN68

 drivers/net/usb/r8152.c | 1841 +++++++++++++++++++++++++++++----------
 1 file changed, 1391 insertions(+), 450 deletions(-)

-- 
2.34.1
[PATCH net-next v10 08/12] r8152: split RTL_VER_17 into QFN68 and QFN100 package variants
#24441
Author: Chih Kai Hsu
Date: Mon, 30 Nov 2026 06:31
378 lines
21438 bytes
RTL8159 is sold in QFN68 and QFN100 packages, and only QFN68 needs
the u2phy backup-restore patch and enables UPS (in a later patch).
There was previously no way to tell the two apart at runtime, since
both used the same RTL_VER_17.

Split RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100 and
update every switch/case on RTL_VER_17 in the driver to handle both.
Detect the package by reading the new PLA_PKG_DET register
(0xdc48, masked with PKG_MASK = 0x1e) via a new __rtl_get_pkg_det()
helper, called from __rtl_get_hw_ver() when the chip ID is 0x2020:
pkg_det value 0x1e/0x1c selects QFN68 and 0x18/0x1a selects QFN100.
A genuine RTL8159 reports one of these, so any other value is a part
the driver does not know and logs "Unknown package".  A failed read
of the register is logged separately.  Both yield RTL_VER_UNKNOWN,
which rtl8152_probe() and the configuration selector reject with
-ENODEV.  Before this patch every 0x2020 chip became RTL_VER_17, so a
chip whose package cannot be identified no longer binds to r8152.

Skipping only the firmware would not be enough, as the package also
selects the QFN68-only u2phy backup-restore write in r8157_init() and,
in a later patch, whether UPS is enabled.  Guessing could apply them
to a part that does not support them.

The package register is read independently by the configuration
selector, rtl8152_probe() and r8153_ecm_probe().  If the selector's
read succeeds and the one in rtl8152_probe() fails after its retries,
the device is left in vendor mode without a driver.  A genuine RTL8159
can only be treated as unknown through such a read failure, which
means the device is in trouble anyway.

QFN100 uses a different firmware image from QFN68, so rtl_fw_init()
selects rtl8159-2.fw for it and keeps rtl8159-1.fw for QFN68.

r8157_init() gains a QFN68-only write ("Enable u2phy backup restore
patch", 0xb99c BIT(0)) that does not apply to QFN100.

Signed-off-by: Chih Kai Hsu <hsu.chih.kai@realtek.com>
---
 drivers/net/usb/r8152.c | 122 ++++++++++++++++++++++++++++++++--------
 1 file changed, 100 insertions(+), 22 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 3e16d0f832bc3..103d8430da424 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -64,6 +64,7 @@
 #define PLA_MACDBG_POST		0xd38e	/* RTL_VER_04 only */
 #define PLA_EXTRA_STATUS	0xd398
 #define PLA_GPHY_CTRL		0xd3ae
+#define PLA_PKG_DET		0xdc48
 #define PLA_POL_GPIO_CTRL	0xdc6a
 #define PLA_EFUSE_DATA		0xdd00
 #define PLA_EFUSE_CMD		0xdd02
@@ -291,6 +292,9 @@
 #define IFG_144NS		BIT(9)
 #define IFG_96NS		(BIT(9) | BIT(8))
 
+/* PLA_PKG_DET */
+#define PKG_MASK		0x1e
+
 /* PLA_MTPS */
 #define MTPS_JUMBO		(12 * 1024 / 64)
 #define MTPS_DEFAULT		(6 * 1024 / 64)
@@ -1258,7 +1262,8 @@ enum rtl_version {
 	RTL_VER_14,
 	RTL_VER_15,
 	RTL_VER_16,
-	RTL_VER_17,
+	RTL_VER_17_QFN68,
+	RTL_VER_17_QFN100,
 
 	RTL_VER_MAX
 };
@@ -3423,7 +3428,8 @@ static void rtl8152_nic_reset(struct r8152 *tp)
 		break;
 
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_CR, CR_RE | CR_TE);
 		break;
 
@@ -3463,7 +3469,7 @@ static void rtl_eee_plus_en(struct r8152 *tp, bool enable)
 
 static void rtl_set_eee_plus(struct r8152 *tp)
 {
-	if (tp->version == RTL_VER_17)
+	if (tp->version == RTL_VER_17_QFN68 || tp->version == RTL_VER_17_QFN100)
 		return rtl_eee_plus_en(tp, false);
 
 	if (rtl8152_get_speed(tp) & _10bps)
@@ -3651,7 +3657,8 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)
 	case RTL_VER_13:
 	case RTL_VER_15:
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
 			       640 / 8);
 		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,
@@ -3696,7 +3703,8 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
 			       ocp_data / 8);
 		break;
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,
 			       ocp_data / 16);
 		break;
@@ -3812,6 +3820,8 @@ static void rtl_rx_vlan_en(struct r8152 *tp, bool enable)
 	case RTL_VER_13:
 	case RTL_VER_15:
 	case RTL_VER_16:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 	default:
 		if (enable)
 			ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_RCR1,
@@ -4492,6 +4502,8 @@ static void r8153_teredo_off(struct r8152 *tp)
 	case RTL_VER_14:
 	case RTL_VER_15:
 	case RTL_VER_16:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 	default:
 		/* The bit 0 ~ 7 are relative with teredo settings. They are
 		 * W1C (write 1 to clear), so set all 1 to disable it.
@@ -4546,7 +4558,8 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
 		break;
 	case RTL_VER_14:
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 	default:
 		ocp_write_word(tp, type, USB_BP2_EN, 0);
 		bp_num = 16;
@@ -4658,7 +4671,8 @@ static bool rtl8152_is_fw_phy_speed_up_ok(struct r8152 *tp, struct fw_phy_speed_
 	case RTL_VER_13:
 	case RTL_VER_15:
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 	default:
 		break;
 	}
@@ -4905,7 +4919,8 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
 			break;
 		case RTL_VER_14:
 		case RTL_VER_16:
-		case RTL_VER_17:
+		case RTL_VER_17_QFN68:
+		case RTL_VER_17_QFN100:
 			fw_reg = 0xf800;
 			bp_ba_addr = PLA_BP_BA;
 			bp_en_addr = USB_BP2_EN;
@@ -4935,7 +4950,8 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
 		case RTL_VER_14:
 		case RTL_VER_15:
 		case RTL_VER_16:
-		case RTL_VER_17:
+		case RTL_VER_17_QFN68:
+		case RTL_VER_17_QFN100:
 			fw_reg = 0xe600;
 			bp_ba_addr = USB_BP_BA;
 			bp_en_addr = USB_BP2_EN;
@@ -5822,7 +5838,8 @@ static void rtl_eee_enable(struct r8152 *tp, bool enable)
 	case RTL_VER_13:
 	case RTL_VER_15:
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		if (enable) {
 			r8156_eee_en(tp, true);
 			ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv);
@@ -6013,7 +6030,8 @@ static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)
 		ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
 		break;
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
 
 		num_pause_pkts = 0xa;
@@ -6512,7 +6530,7 @@ static int rtl8156_enable(struct r8152 *tp)
 	set_tx_qlen(tp);
 	rtl_set_eee_plus(tp);
 
-	if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_17)
+	if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_17_QFN100)
 		ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
 
 	r8153_set_rx_early_timeout(tp);
@@ -7008,7 +7026,8 @@ static void rtl8156_up(struct r8152 *tp)
 		ocp_word_set_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(15));
 		break;
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		/* Enable Clear_SDR */
 		ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xd378, BIT(7));
 		/* Clear SDR bit */
@@ -7052,7 +7071,8 @@ static void rtl8156_down(struct r8152 *tp)
 
 	switch (tp->version) {
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1526);
 		ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64);
 		break;
@@ -8258,7 +8278,8 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
 		sram2_write_w0w1(tp, 0x809d, 0xff00, 0x5000);
 		break;
 
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		/* Disable bypass turn off clk in ALDPS */
 		ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
 
@@ -8652,7 +8673,8 @@ static void r8157_init(struct r8152 *tp)
 		return;
 
 	switch (tp->version) {
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		if (r8159_wait_backup_restore(tp)) {
 			rtl_set_inaccessible(tp);
 			dev_err(&tp->intf->dev,
@@ -8699,7 +8721,8 @@ static void r8157_init(struct r8152 *tp)
 	ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));
 
 	switch (tp->version) {
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		/* Disable FW u1u2 patch option */
 		ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xb9a6, BIT(0));
 		break;
@@ -8737,7 +8760,11 @@ static void r8157_init(struct r8152 *tp)
 	ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
 
 	switch (tp->version) {
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+		/* Enable u2phy backup restore patch */
+		ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xb99c, BIT(0));
+		fallthrough;
+	case RTL_VER_17_QFN100:
 		/* Enable u3phy patch backup */
 		ocp_write_word(tp, MCU_TYPE_USB, 0xb9a2, 0x0448);
 		break;
@@ -10131,7 +10158,8 @@ static int rtl_ops_init(struct r8152 *tp)
 		r8157_desc_init(tp);
 		break;
 
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		tp->eee_en		= true;
 		tp->eee_adv		= MDIO_EEE_100TX | MDIO_EEE_1000T | MDIO_EEE_10GT;
 		tp->eee_adv2		= MDIO_EEE_2_5GT | MDIO_EEE_5GT;
@@ -10172,6 +10200,7 @@ static int rtl_ops_init(struct r8152 *tp)
 #define FIRMWARE_8156B_2	"rtl_nic/rtl8156b-2.fw"
 #define FIRMWARE_8157_1		"rtl_nic/rtl8157-1.fw"
 #define FIRMWARE_8159_1		"rtl_nic/rtl8159-1.fw"
+#define FIRMWARE_8159_2		"rtl_nic/rtl8159-2.fw"
 
 MODULE_FIRMWARE(FIRMWARE_8153A_2);
 MODULE_FIRMWARE(FIRMWARE_8153A_3);
@@ -10182,6 +10211,7 @@ MODULE_FIRMWARE(FIRMWARE_8156A_2);
 MODULE_FIRMWARE(FIRMWARE_8156B_2);
 MODULE_FIRMWARE(FIRMWARE_8157_1);
 MODULE_FIRMWARE(FIRMWARE_8159_1);
+MODULE_FIRMWARE(FIRMWARE_8159_2);
 
 static int rtl_fw_init(struct r8152 *tp)
 {
@@ -10223,9 +10253,12 @@ static int rtl_fw_init(struct r8152 *tp)
 	case RTL_VER_16:
 		rtl_fw->fw_name		= FIRMWARE_8157_1;
 		break;
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
 		rtl_fw->fw_name		= FIRMWARE_8159_1;
 		break;
+	case RTL_VER_17_QFN100:
+		rtl_fw->fw_name		= FIRMWARE_8159_2;
+		break;
 	default:
 		break;
 	}
@@ -10233,9 +10266,40 @@ static int rtl_fw_init(struct r8152 *tp)
 	return 0;
 }
 
+static int __rtl_get_pkg_det(struct usb_device *udev, u32 *pkg_det)
+{
+	__le32 *tmp;
+	int ret, i;
+
+	tmp = kmalloc_obj(*tmp);
+	if (!tmp)
+		return -ENOMEM;
+
+	for (i = 0, ret = 0; i < 3 && ret != 4; i++)
+		ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+				      RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
+				      PLA_PKG_DET, MCU_TYPE_PLA, tmp,
+				      sizeof(*tmp), USB_CTRL_GET_TIMEOUT);
+
+	if (ret == sizeof(*tmp)) {
+		if (i != 1)
+			dev_warn(&udev->dev,
+				 "Needed %d retries to read package\n", i - 1);
+
+		*pkg_det = __le32_to_cpu(*tmp) & PKG_MASK;
+		ret = 0;
+	} else if (ret >= 0) {
+		ret = -EIO;
+	}
+
+	kfree(tmp);
+	return ret;
+}
+
 static u8 __rtl_get_hw_ver(struct usb_device *udev)
 {
 	u32 ocp_data = 0;
+	u32 pkg_det = 0;
 	__le32 *tmp;
 	u8 version;
 	int ret;
@@ -10318,7 +10382,20 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev)
 		version = RTL_VER_16;
 		break;
 	case 0x2020:
-		version = RTL_VER_17;
+		ret = __rtl_get_pkg_det(udev, &pkg_det);
+		if (ret < 0) {
+			version = RTL_VER_UNKNOWN;
+			dev_err(&udev->dev, "Failed to read package: %d\n",
+				ret);
+		} else if (pkg_det == 0x1e || pkg_det == 0x1c) {
+			version = RTL_VER_17_QFN68;
+		} else if (pkg_det == 0x18 || pkg_det == 0x1a) {
+			version = RTL_VER_17_QFN100;
+		} else {
+			version = RTL_VER_UNKNOWN;
+			dev_err(&udev->dev, "Unknown package 0x%04x\n",
+				pkg_det);
+		}
 		break;
 	default:
 		version = RTL_VER_UNKNOWN;
@@ -10477,7 +10554,8 @@ static int rtl8152_probe_once(struct usb_interface *intf,
 	case RTL_VER_13:
 	case RTL_VER_15:
 	case RTL_VER_16:
-	case RTL_VER_17:
+	case RTL_VER_17_QFN68:
+	case RTL_VER_17_QFN100:
 		netdev->max_mtu = size_to_mtu(16 * 1024);
 		break;
 	case RTL_VER_01:
-- 
2.34.1
[PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
#24440
Author: Chih Kai Hsu
Date: Mon, 30 Nov 2026 06:31
234 lines
16175 bytes
RTL8157 and RTL8159 QFN68 support UPS, but rtl8157_runtime_enable()
never toggled it on runtime suspend/resume, and r8156_ups_flags()
used the older per-chip EEE/lite_mode encoding instead of the
per-speed EEE flags their UPS firmware expects. RTL8159 QFN100 does
not support UPS.

Add r8157_ups_en(), mirroring r8156_ups_en(), and call it from
rtl8157_runtime_enable() for VER_16/QFN68 only; QFN100 keeps its
existing no-UPS behaviour there. Use r8157_ups_en(tp, false) in
r8157_init() in place of r8156_ups_en(tp, false).

Extend r8156_ups_flags() with per-speed EEE flags
(UPS_FLAGS_EN_100M_EEE/1000M_EEE/2500M_EEE/5000M_EEE/10G_EEE) and
skip the lite_mode bits[6:5] encoding for VER_16/QFN68. Add
ups_flags_speed() entries 10 and 11 for NWAY_5000M_FULL and
NWAY_10000M_FULL, previously unmapped.

Add the USB_FW_USB_VER register (0xcfd7), used by the new
r8157_ups_en() disable path.  A power cut clears the PLA firmware
version register along with the patch, but the USB one survives while
the USB patch is lost.  rtl8152_fw_mac_apply() skips a block whose
version register is already current, so the disable path clears the USB
version before hw_phy_cfg() applies the firmware again.

The disable path waits for the backup-restore to finish after a power
cut on RTL8157 as well as RTL8159, before reconfiguring the PHY.  If
that wait in r8157_ups_en() times out, it marks the device inaccessible
and logs, without queuing a reset, as r8157_init() does for RTL8159.
During runtime resume the interface then stays unusable until a replug
or an unrelated reset, since r8157_ups_en() returns void and the error
is not passed back.  Recovery for these timeouts is left to a follow-up
series.

Signed-off-by: Chih Kai Hsu <hsu.chih.kai@realtek.com>
---
 drivers/net/usb/r8152.c | 131 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 120 insertions(+), 11 deletions(-)

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
@@ -132,6 +132,7 @@
 #define USB_BURST_SIZE		0xcfc0
 #define USB_FW_FIX_EN0		0xcfca
 #define USB_FW_FIX_EN1		0xcfcc
+#define USB_FW_USB_VER		0xcfd7
 #define USB_LPM_CONFIG		0xcfd8
 #define USB_ECM_OPTION		0xcfee
 #define USB_CSTMR		0xcfef	/* RTL8153A */
@@ -619,6 +620,11 @@
 #define UPS_FLAGS_250M_CKDIV		BIT(2)
 #define UPS_FLAGS_EN_ALDPS		BIT(3)
 #define UPS_FLAGS_CTAP_SHORT_DIS	BIT(4)
+#define UPS_FLAGS_EN_100M_EEE		BIT(9)
+#define UPS_FLAGS_EN_1000M_EEE		BIT(10)
+#define UPS_FLAGS_EN_2500M_EEE		BIT(11)
+#define UPS_FLAGS_EN_5000M_EEE		BIT(12)
+#define UPS_FLAGS_EN_10G_EEE		BIT(13)
 #define UPS_FLAGS_SPEED_MASK		(0xf << 16)
 #define ups_flags_speed(x)		((x) << 16)
 #define UPS_FLAGS_EN_EEE		BIT(20)
@@ -4256,8 +4262,27 @@ static void r8156_ups_flags(struct r8152 *tp)
 	if (tp->ups_info.aldps)
 		ups_flags |= UPS_FLAGS_EN_ALDPS;
 
-	if (tp->ups_info.eee)
-		ups_flags |= UPS_FLAGS_EN_EEE;
+	if (tp->ups_info.eee) {
+		switch (tp->version) {
+		case RTL_VER_17_QFN68:
+			if (tp->eee_adv & MDIO_EEE_10GT)
+				ups_flags |= UPS_FLAGS_EN_10G_EEE;
+			fallthrough;
+		case RTL_VER_16:
+			if (tp->eee_adv & MDIO_EEE_100TX)
+				ups_flags |= UPS_FLAGS_EN_100M_EEE;
+			if (tp->eee_adv & MDIO_EEE_1000T)
+				ups_flags |= UPS_FLAGS_EN_1000M_EEE;
+			if (tp->eee_adv2 & MDIO_EEE_2_5GT)
+				ups_flags |= UPS_FLAGS_EN_2500M_EEE;
+			if (tp->eee_adv2 & MDIO_EEE_5GT)
+				ups_flags |= UPS_FLAGS_EN_5000M_EEE;
+			break;
+		default:
+			ups_flags |= UPS_FLAGS_EN_EEE;
+			break;
+		}
+	}
 
 	if (tp->ups_info.flow_control)
 		ups_flags |= UPS_FLAGS_EN_FLOW_CTR;
@@ -4308,20 +4333,33 @@ static void r8156_ups_flags(struct r8152 *tp)
 	case NWAY_2500M_FULL:
 		ups_flags |= ups_flags_speed(9);
 		break;
+	case NWAY_5000M_FULL:
+		ups_flags |= ups_flags_speed(10);
+		break;
+	case NWAY_10000M_FULL:
+		ups_flags |= ups_flags_speed(11);
+		break;
 	default:
 		break;
 	}
 
-	switch (tp->ups_info.lite_mode) {
-	case 1:
-		ups_flags |= 0 << 5;
-		break;
-	case 2:
-		ups_flags |= 2 << 5;
+	switch (tp->version) {
+	case RTL_VER_16:
+	case RTL_VER_17_QFN68:
 		break;
-	case 0:
 	default:
-		ups_flags |= 1 << 5;
+		switch (tp->ups_info.lite_mode) {
+		case 1:
+			ups_flags |= 0 << 5;
+			break;
+		case 2:
+			ups_flags |= 2 << 5;
+			break;
+		case 0:
+		default:
+			ups_flags |= 1 << 5;
+			break;
+		}
 		break;
 	}
 
@@ -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;
+			}
+
+			/* 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;
+		}
+
 		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);
 
-- 
2.34.1
Re: [PATCH net-next v10 00/12] r8152: refactor and extend RTL8157/8159 support
#24442
Author: netdev-bot+sinfo
Date: Mon, 30 Nov 2026 06:35
19 lines
8427 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net-next v10 08/12] r8152: split RTL_VER_17 into QFN68 and QFN100 package variants
#25008
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 06:46
92 lines
11072 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] This patch silently changes which firmware every existing
  QFN100 RTL8159 user loads, and the commit message does not explain the…

--

r8152: split RTL_VER_17 into QFN68 and QFN100 package variants

This splits RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100. The
package is detected by reading PLA_PKG_DET in __rtl_get_hw_ver(), and
parts that cannot be identified are rejected. It also selects a new
rtl8159-2.fw image for QFN100 and adds a QFN68-only u2phy backup-restore
write in r8157_init().

> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 3e16d0f832bc3..103d8430da424 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c

[ ... ]

> @@ -10223,9 +10253,12 @@ static int rtl_fw_init(struct r8152 *tp)
>  	case RTL_VER_16:
>  		rtl_fw->fw_name		= FIRMWARE_8157_1;
>  		break;
> -	case RTL_VER_17:
> +	case RTL_VER_17_QFN68:
>  		rtl_fw->fw_name		= FIRMWARE_8159_1;
>  		break;
> +	case RTL_VER_17_QFN100:
> +		rtl_fw->fw_name		= FIRMWARE_8159_2;
> +		break;
>  	default:
>  		break;
>  	}

[Severity: Medium]
This changes the firmware that existing QFN100 RTL8159 users load. Before
this patch every 0x2020 chip became RTL_VER_17, so QFN100 parts loaded
rtl8159-1.fw. After it, QFN100 requests rtl8159-2.fw, and nothing falls
back to rtl8159-1.fw.

The commit message only says:

    QFN100 uses a different firmware image from QFN68, so rtl_fw_init()
    selects rtl8159-2.fw for it and keeps rtl8159-1.fw for QFN68.

RTL8159 firmware loading has been in the tree since commit a51e171e176c
("r8152: Add firmware upload capability for RTL8157/RTL8159"). Released
kernels have therefore been applying rtl8159-1.fw to QFN100 parts.

Was that harmful on QFN100? If so, this patch fixes a user-visible bug.
Should the commit message then describe the symptom and carry a Fixes:
tag?

This also adds a dependency on a new linux-firmware blob. If the blob is
missing, rtl8152_request_firmware() only warns:

	if (rc) {
		rtl_fw->fw = ERR_PTR(rc);

		dev_warn(&tp->intf->dev,
			 "unable to load firmware patch %s (%ld)\n",
			 rtl_fw->fw_name, rc);
	}

Commit a51e171e176c says the RTL8159 needs its PHY firmware to work at
speeds above 5GBit. A QFN100 user who upgrades the kernel without
rtl8159-2.fw installed goes from having a PHY firmware patch to having
none, and only sees a warning in the log. Can that drop links above 5G
on QFN100?

Could the commit message mention the new rtl8159-2.fw requirement and
whether it is already in linux-firmware? If rtl8159-1.fw was not harmful
on QFN100, would a fallback to it be worth adding when rtl8159-2.fw
cannot be loaded?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130063123.2408-1-nic_swsd%40realtek.com
Re: [PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
#25011
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 06:46
298 lines
18713 bytes
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
RE: [PATCH net-next v10 08/12] r8152: split RTL_VER_17 into QFN68 and QFN100 package variants
#25216
Author: Chih Kai Hsu
Date: Tue, 01 Dec 2026 12:14
71 lines
15043 bytes
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
> 
> 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] This patch silently changes which firmware every existing
>   QFN100 RTL8159 user loads, and the commit message does not explain the…
> 
> --
> 
> r8152: split RTL_VER_17 into QFN68 and QFN100 package variants
> 
> This splits RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100.
> The package is detected by reading PLA_PKG_DET in __rtl_get_hw_ver(), and
> parts that cannot be identified are rejected. It also selects a new rtl8159-2.fw
> image for QFN100 and adds a QFN68-only u2phy backup-restore write in
> r8157_init().
> 
> > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index
> > 3e16d0f832bc3..103d8430da424 100644
> > --- a/drivers/net/usb/r8152.c
> > +++ b/drivers/net/usb/r8152.c
> 
> [ ... ]
> 
> > @@ -10223,9 +10253,12 @@ static int rtl_fw_init(struct r8152 *tp)
> >       case RTL_VER_16:
> >               rtl_fw->fw_name         = FIRMWARE_8157_1;
> >               break;
> > -     case RTL_VER_17:
> > +     case RTL_VER_17_QFN68:
> >               rtl_fw->fw_name         = FIRMWARE_8159_1;
> >               break;
> > +     case RTL_VER_17_QFN100:
> > +             rtl_fw->fw_name         = FIRMWARE_8159_2;
> > +             break;
> >       default:
> >               break;
> >       }
> 
> [Severity: Medium]
> This changes the firmware that existing QFN100 RTL8159 users load. Before this
> patch every 0x2020 chip became RTL_VER_17, so QFN100 parts loaded
> rtl8159-1.fw. After it, QFN100 requests rtl8159-2.fw, and nothing falls back to
> rtl8159-1.fw.
> 
> The commit message only says:
> 
>     QFN100 uses a different firmware image from QFN68, so rtl_fw_init()
>     selects rtl8159-2.fw for it and keeps rtl8159-1.fw for QFN68.
> 
> RTL8159 firmware loading has been in the tree since commit a51e171e176c
> ("r8152: Add firmware upload capability for RTL8157/RTL8159"). Released
> kernels have therefore been applying rtl8159-1.fw to QFN100 parts.
> 
> Was that harmful on QFN100? If so, this patch fixes a user-visible bug.
> Should the commit message then describe the symptom and carry a Fixes:
> tag?
> 
> This also adds a dependency on a new linux-firmware blob. If the blob is missing,
> rtl8152_request_firmware() only warns:
> 
>         if (rc) {
>                 rtl_fw->fw = ERR_PTR(rc);
> 
>                 dev_warn(&tp->intf->dev,
>                          "unable to load firmware patch %s (%ld)\n",
>                          rtl_fw->fw_name, rc);
>         }
> 
> Commit a51e171e176c says the RTL8159 needs its PHY firmware to work at
> speeds above 5GBit. A QFN100 user who upgrades the kernel without
> rtl8159-2.fw installed goes from having a PHY firmware patch to having none,
> and only sees a warning in the log. Can that drop links above 5G on QFN100?
> 
> Could the commit message mention the new rtl8159-2.fw requirement and
> whether it is already in linux-firmware? If rtl8159-1.fw was not harmful on
> QFN100, would a fallback to it be worth adding when rtl8159-2.fw cannot be
> loaded?

The QFN68 image has not been validated on QFN100. There is no fallback
to it. If rtl8159-2.fw cannot be loaded, the driver warns and continues
without PHY firmware, as for any other missing image.

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

Best Regards,
Chih-Kai
RE: [PATCH net-next v10 12/12] r8152: enable UPS for RTL8157 and RTL8159 QFN68
#25220
Author: Chih Kai Hsu
Date: Tue, 01 Dec 2026 12:21
232 lines
27574 bytes
> 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?

Yes, that is 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 two chips shouldn't wait for autoload.

> 
> 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?

Waiting backup-restore is intended for RTL8157 when resuming from
UPS.

> 
> 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?

As I said in the previous version, this matches how the existing timeout in
r8157_init() behaves.

Recovery from the timeout requires more than just queuing a reset. The reset
has to survive a re-autosuspend and rerun init() in rtl8152_post_reset(), and the
runtime resume path has to report the failure.

> 
> 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()?

Yes, if the device entered UPS, the PCUT_STATUS would be set to 1.

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

Best Regards,
Chih-Kai
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads