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 <rene.sapiens@linux.intel.com>
Signed-off-by: Rene Sapiens <rene.sapiens@linux.intel.com>
Signed-off-by: Anurag <anurag@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
This commit is contained in:
Anurag 2026-08-27 17:18:48 -07:00 committed by Mika Westerberg
parent 879519402c
commit d224aacc8c

View File

@ -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);
}