Linux USB
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Anton Bulakh <him@necauq.ua>
Subject: [PATCH 04/10] xhci: Fix reporting incorrect supported speeds in roothub BOS descriptor
Date: Fri, 27 Nov 2026 14:17:49 +0200	[thread overview]
Message-ID: <20261127121755.281420-5-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20261127121755.281420-1-mathias.nyman@linux.intel.com>

xhci driver can show incorrect supported speeds for roothub ports if the
xHC controller lists several port protocol capabilities with the same
revision but with different supported speeds.

AMD xHCI 1022:149c lists several port protocol capabilities with the
same USB 3.1 revision. Some of these capabilities report that a set of
ports only support 5Gbps, while other capabilities report their ports
support both 5Gbps and 10Gbps.

xhci_create_usb3x_bos_desc() builds the root hub SSP capability from one
port capability only: the first one with the highest revision, ending up
with a roothub BOS SSP capability descriptor claiming that roothub only
supports 5Gbps speeds.

Fix this by picking the port protocol capability with highest revision
and largest unique protocol speed ID count. Prefer a capability with a
protocol speed ID count of 0, as that means its ports support all
default speeds of that USB revision.

This won't guarantee that the supported speeds of all protocol
capabilities are listed in the BOS descriptor, but it's an improvement
over the current situation.

Reported-by: Anton Bulakh <him@necauq.ua>
Closes: https://lore.kernel.org/linux-usb/8a954797-4eb4-44db-b53f-6e83f4b7b03a@necauq.ua/
Tested-by: Anton Bulakh <him@necauq.ua>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 55430b673f1e..d47d1e736a37 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -59,13 +59,20 @@ static int xhci_create_usb3x_bos_desc(struct xhci_hcd *xhci, char *buf,
 
 	/* Create the descriptor for port with the highest revision */
 	for (i = 0; i < xhci->num_port_caps; i++) {
-		u8 major = xhci->port_caps[i].maj_rev;
-		u8 minor = xhci->port_caps[i].min_rev;
-		u16 rev = (major << 8) | minor;
+		struct xhci_port_cap *cap = &xhci->port_caps[i];
+		u16 rev = (cap->maj_rev << 8) | cap->min_rev;
 
 		if (i == 0 || bcdUSB < rev) {
 			bcdUSB = rev;
-			port_cap = &xhci->port_caps[i];
+			port_cap = cap;
+		} else if (bcdUSB == rev && port_cap->psi_count != 0) {
+			/*
+			 * Same revision: prefer psi_count 0 (all default speeds),
+			 * otherwise the highest psi_uid_count.
+			 */
+			if (cap->psi_count == 0 ||
+			    cap->psi_uid_count > port_cap->psi_uid_count)
+				port_cap = cap;
 		}
 	}
 
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 12:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:17 [PATCH 00/10] xhci fixes for usb-linus Mathias Nyman
2026-11-27 12:17 ` [PATCH 01/10] usb: xhci: Fix ep0 maxpacket update on enabled slots Mathias Nyman
2026-11-27 12:17 ` [PATCH 02/10] xhci: check for halted host before accessing virt devices in xhci_check_args() Mathias Nyman
2026-11-27 12:17 ` [PATCH 03/10] xhci: Give back URB under lock in xhci_urb_dequeue() Mathias Nyman
2026-11-27 12:17 ` Mathias Nyman [this message]
2026-11-27 12:17 ` [PATCH 05/10] xhci: sideband: avoid use-after-free of stale virt device pointer Mathias Nyman
2026-11-27 12:17 ` [PATCH 06/10] xhci: sideband: check virt device under xhci lock when stopping endpoints Mathias Nyman
2026-11-27 12:17 ` [PATCH 07/10] usb: xhci: tegra: Fix missing semi-colon Mathias Nyman
2026-11-27 12:17 ` [PATCH 08/10] usb: xhci: Demote isoch buffer overrun message to debug level Mathias Nyman
2026-11-27 12:17 ` [PATCH 09/10] xhci: fix use-after-free for errors mid TD on empty halted rings Mathias Nyman
2026-11-27 12:17 ` [PATCH 10/10] xhci: fix NULL pointer dereference of rhub_port in xhci_urb_enqueue() Mathias Nyman
2026-11-27 12:28 ` [PATCH 00/10] xhci fixes for usb-linus sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127121755.281420-5-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=him@necauq.ua \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox