Skip to content

Commit 551216a

Browse files
Caveh JalaliPatrick Georgi
authored andcommitted
xhci: Fix Abort command event handling
This fixes issues with how we handle events generated by the xHCI "command abort" command. first, depending on the state of the xHCI controller, the COMMAND_ABORTED may not be generated. If the controller was between commands, only the COMMAND_RING_STOPPED event will be generated. Second, do not adjust the command ring "cur" pointer as that just confuses the controller. BUG=b:160354585,b:157123390 TEST=able to boot into recovery using USB stick on servo v2 on volteer as well as HooToo 8-1 hub Change-Id: I055df680d1797f35d9730e2bfdb4119925657168 Signed-off-by: Caveh Jalali <[email protected]> Reviewed-on: https://review.coreboot.org/c/coreboot/+/44875 Tested-by: build bot (Jenkins) <[email protected]> Reviewed-by: Julius Werner <[email protected]>
1 parent 1d84941 commit 551216a

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

payloads/libpayload/drivers/usb/xhci_events.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,15 @@ xhci_wait_for_event_type(xhci_t *const xhci,
226226
return *timeout_us;
227227
}
228228

229-
/* returns cc of command in question (pointed to by `address`) */
229+
/*
230+
* Ref. xHCI Specification Revision 1.2, May 2019.
231+
* Section 4.6.1.2.
232+
*
233+
* Process events from xHCI Abort command.
234+
*
235+
* Returns CC_COMMAND_RING_STOPPED on success and TIMEOUT on failure.
236+
*/
237+
230238
int
231239
xhci_wait_for_command_aborted(xhci_t *const xhci, const trb_t *const address)
232240
{
@@ -239,33 +247,45 @@ xhci_wait_for_command_aborted(xhci_t *const xhci, const trb_t *const address)
239247
int cc = TIMEOUT;
240248
/*
241249
* Expects two command completion events:
242-
* The first with CC == COMMAND_ABORTED should point to address,
250+
* The first with CC == COMMAND_ABORTED should point to address
251+
* (not present if command was not running),
243252
* the second with CC == COMMAND_RING_STOPPED should point to new dq.
244253
*/
245254
while (xhci_wait_for_event_type(xhci, TRB_EV_CMD_CMPL, &timeout_us)) {
246255
if ((xhci->er.cur->ptr_low == virt_to_phys(address)) &&
247-
(xhci->er.cur->ptr_high == 0)) {
256+
(xhci->er.cur->ptr_high == 0)) {
248257
cc = TRB_GET(CC, xhci->er.cur);
249258
xhci_advance_event_ring(xhci);
250259
break;
251260
}
252261

253262
xhci_handle_command_completion_event(xhci);
254263
}
255-
if (!timeout_us)
256-
xhci_debug("Warning: Timed out waiting for COMMAND_ABORTED.\n");
264+
if (timeout_us == 0) {
265+
xhci_debug("Warning: Timed out waiting for "
266+
"COMMAND_ABORTED or COMMAND_RING_STOPPED.\n");
267+
goto update_and_return;
268+
}
269+
if (cc == CC_COMMAND_RING_STOPPED) {
270+
/* There may not have been a command to abort. */
271+
goto update_and_return;
272+
}
273+
274+
timeout_us = USB_MAX_PROCESSING_TIME_US; /* 5s */
257275
while (xhci_wait_for_event_type(xhci, TRB_EV_CMD_CMPL, &timeout_us)) {
258276
if (TRB_GET(CC, xhci->er.cur) == CC_COMMAND_RING_STOPPED) {
259-
xhci->cr.cur = phys_to_virt(xhci->er.cur->ptr_low);
277+
cc = CC_COMMAND_RING_STOPPED;
260278
xhci_advance_event_ring(xhci);
261279
break;
262280
}
263281

264282
xhci_handle_command_completion_event(xhci);
265283
}
266-
if (!timeout_us)
284+
if (timeout_us == 0)
267285
xhci_debug("Warning: Timed out "
268286
"waiting for COMMAND_RING_STOPPED.\n");
287+
288+
update_and_return:
269289
xhci_update_event_dq(xhci);
270290
return cc;
271291
}

0 commit comments

Comments
 (0)