From d224aacc8cf333700257fe0936f701848c2ea1b8 Mon Sep 17 00:00:00 2001 From: Anurag Date: Thu, 27 Aug 2026 17:18:48 -0700 Subject: [PATCH] thunderbolt: Fix sideband register access in usb4_port_sw_margin_errors() The READ_SW_MARGIN_ERR (RDSW) completion payload is returned in the USB4 sideband data window, but the location differs between standard and extended error counters. Standard error counters are returned in USB4_SB_METADATA and fit within a single dword. Extended error counters require 4 dwords and are returned in USB4_SB_DATA. Add conditional logic to select the appropriate register based on the dwords parameter that corresponds with error counter type. Co-developed-by: Rene Sapiens Signed-off-by: Rene Sapiens Signed-off-by: Anurag Signed-off-by: Mika Westerberg --- drivers/thunderbolt/usb4.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c index fe1b061f7055..c9b3931c45ed 100644 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -1836,13 +1836,16 @@ int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, u8 index, u32 *errors, size_t dwords) { int ret; + u8 reg; ret = usb4_port_sb_op(port, target, index, USB4_SB_OPCODE_READ_SW_MARGIN_ERR, 150); if (ret) return ret; - return usb4_port_sb_read(port, target, index, USB4_SB_METADATA, errors, + reg = (dwords > 1) ? USB4_SB_DATA : USB4_SB_METADATA; + + return usb4_port_sb_read(port, target, index, reg, errors, sizeof(*errors) * dwords); }