Skip to content

Commit 7dbdb53

Browse files
thejhgregkh
authored andcommitted
USB: early: Handle AMD's spec-compliant identifiers, too
This fixes a bug that causes the USB3 early console to freeze after printing a single line on AMD machines because it can't parse the Transfer TRB properly. The spec at https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf says in section "4.5.1 Device Context Index" that the Context Index, also known as Endpoint ID according to section "1.6 Terms and Abbreviations", is normally computed as `DCI = (Endpoint Number * 2) + Direction`, which matches the current definitions of XDBC_EPID_OUT and XDBC_EPID_IN. However, the numbering in a Debug Capability Context data structure is supposed to be different: Section "7.6.3.2 Endpoint Contexts and Transfer Rings" explains that a Debug Capability Context data structure has the endpoints mapped to indices 0 and 1. Change XDBC_EPID_OUT/XDBC_EPID_IN to the spec-compliant values, add XDBC_EPID_OUT_INTEL/XDBC_EPID_IN_INTEL with Intel's incorrect values, and let xdbc_handle_tx_event() handle both. I have verified that with this patch applied, the USB3 early console works on both an Intel and an AMD machine. Fixes: aeb9dd1 ("usb/early: Add driver for xhci debug capability") Cc: [email protected] Signed-off-by: Jann Horn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 056ad39 commit 7dbdb53

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

drivers/usb/early/xhci-dbc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,19 @@ static void xdbc_handle_tx_event(struct xdbc_trb *evt_trb)
728728
case COMP_USB_TRANSACTION_ERROR:
729729
case COMP_STALL_ERROR:
730730
default:
731-
if (ep_id == XDBC_EPID_OUT)
731+
if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL)
732732
xdbc.flags |= XDBC_FLAGS_OUT_STALL;
733-
if (ep_id == XDBC_EPID_IN)
733+
if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL)
734734
xdbc.flags |= XDBC_FLAGS_IN_STALL;
735735

736736
xdbc_trace("endpoint %d stalled\n", ep_id);
737737
break;
738738
}
739739

740-
if (ep_id == XDBC_EPID_IN) {
740+
if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL) {
741741
xdbc.flags &= ~XDBC_FLAGS_IN_PROCESS;
742742
xdbc_bulk_transfer(NULL, XDBC_MAX_PACKET, true);
743-
} else if (ep_id == XDBC_EPID_OUT) {
743+
} else if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL) {
744744
xdbc.flags &= ~XDBC_FLAGS_OUT_PROCESS;
745745
} else {
746746
xdbc_trace("invalid endpoint id %d\n", ep_id);

drivers/usb/early/xhci-dbc.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,22 @@ struct xdbc_ring {
120120
u32 cycle_state;
121121
};
122122

123-
#define XDBC_EPID_OUT 2
124-
#define XDBC_EPID_IN 3
123+
/*
124+
* These are the "Endpoint ID" (also known as "Context Index") values for the
125+
* OUT Transfer Ring and the IN Transfer Ring of a Debug Capability Context data
126+
* structure.
127+
* According to the "eXtensible Host Controller Interface for Universal Serial
128+
* Bus (xHCI)" specification, section "7.6.3.2 Endpoint Contexts and Transfer
129+
* Rings", these should be 0 and 1, and those are the values AMD machines give
130+
* you; but Intel machines seem to use the formula from section "4.5.1 Device
131+
* Context Index", which is supposed to be used for the Device Context only.
132+
* Luckily the values from Intel don't overlap with those from AMD, so we can
133+
* just test for both.
134+
*/
135+
#define XDBC_EPID_OUT 0
136+
#define XDBC_EPID_IN 1
137+
#define XDBC_EPID_OUT_INTEL 2
138+
#define XDBC_EPID_IN_INTEL 3
125139

126140
struct xdbc_state {
127141
u16 vendor;

0 commit comments

Comments
 (0)