From 17834c6af4a9c59ced57dfeea0f7c1c48b771aa3 Mon Sep 17 00:00:00 2001
From: "Chia-Lin Kao (AceLan)" <acelan.kao@canonical.com>
Date: Thu, 19 Mar 2026 11:14:17 +0800
Subject: [PATCH 2/3] xhci: Add debug instrumentation for VDEV_PORT_ERROR
 handling

Add xhci_dbg() traces to the VDEV_PORT_ERROR set/clear path in
handle_port_status() to validate the USB3-only guard added by:

  commit dbbaf9e5f422 ("xhci: restrict VDEV_PORT_ERROR to USB3 ports in handle_port_status()")

The debug messages log:
- When a USB3 port in SS.Inactive (PLS=6) sets VDEV_PORT_ERROR
- When a USB3 port in SS.Inactive (PLS=6) skips VDEV_PORT_ERROR due to
  an active PORT_RESET
- When PORT_RC clears VDEV_PORT_ERROR, including the port speed
- When a USB2 port hits PLS=6 (reserved value), confirming the guard
  prevents incorrect VDEV_PORT_ERROR on USB 2.0 devices

These traces help verify that Thunderbolt 4 docks with Realtek USB 2.0
hubs no longer trigger spurious VDEV_PORT_ERROR during the transient
PLS=6 read that blocked URB queueing.

Signed-off-by: Chia-Lin Kao (AceLan) <acelan.kao@canonical.com>
---
 drivers/usb/host/xhci-ring.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bca44bc13ce75..38d64b5f0d4a4 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2048,10 +2048,22 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
 
 	if (hcd->speed >= HCD_USB3 && vdev &&
 	    (portsc & PORT_PLS_MASK) == XDEV_INACTIVE) {
-		if (!(portsc & PORT_RESET))
+		if (!(portsc & PORT_RESET)) {
+			xhci_dbg(xhci, "port %d: USB3 SS.Inactive (PLS=6), no reset active, setting VDEV_PORT_ERROR\n",
+				 port_id);
 			vdev->flags |= VDEV_PORT_ERROR;
+		} else {
+			xhci_dbg(xhci, "port %d: USB3 SS.Inactive (PLS=6) with PORT_RESET active, skipping VDEV_PORT_ERROR\n",
+				 port_id);
+		}
 	} else if (vdev && portsc & PORT_RC) {
+		xhci_dbg(xhci, "port %d: PORT_RC set, clearing VDEV_PORT_ERROR (speed=%d)\n",
+			 port_id, hcd->speed);
 		vdev->flags &= ~VDEV_PORT_ERROR;
+	} else if (vdev && hcd->speed < HCD_USB3 &&
+		   (portsc & PORT_PLS_MASK) == XDEV_INACTIVE) {
+		xhci_dbg(xhci, "port %d: USB2 port with PLS=6 (SS.Inactive reserved), ignoring VDEV_PORT_ERROR (portsc=0x%08x)\n",
+			 port_id, portsc);
 	}
 
 	if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
-- 
2.53.0

