Skip to content

Commit c786297

Browse files
pawellcdnsgregkh
authored andcommitted
usb: cdnsp: Fix issue with detecting command completion event
commit f4ecdc3 upstream. In some cases, there is a small-time gap in which CMD_RING_BUSY can be cleared by controller but adding command completion event to event ring will be delayed. As the result driver will return error code. This behavior has been detected on usbtest driver (test 9) with configuration including ep1in/ep1out bulk and ep2in/ep2out isoc endpoint. Probably this gap occurred because controller was busy with adding some other events to event ring. The CMD_RING_BUSY is cleared to '0' when the Command Descriptor has been executed and not when command completion event has been added to event ring. To fix this issue for this test the small delay is sufficient less than 10us) but to make sure the problem doesn't happen again in the future the patch introduces 10 retries to check with delay about 20us before returning error code. Fixes: 3d82904 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver") Cc: stable <stable@kernel.org> Signed-off-by: Pawel Laszczak <pawell@cadence.com> Acked-by: Peter Chen <peter.chen@kernel.org> Link: https://lore.kernel.org/r/PH7PR07MB9538AA45362ACCF1B94EE9B7DD96A@PH7PR07MB9538.namprd07.prod.outlook.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3cce173 commit c786297

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

drivers/usb/cdns3/cdnsp-gadget.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev)
546546
dma_addr_t cmd_deq_dma;
547547
union cdnsp_trb *event;
548548
u32 cycle_state;
549+
u32 retry = 10;
549550
int ret, val;
550551
u64 cmd_dma;
551552
u32 flags;
@@ -577,8 +578,23 @@ int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev)
577578
flags = le32_to_cpu(event->event_cmd.flags);
578579

579580
/* Check the owner of the TRB. */
580-
if ((flags & TRB_CYCLE) != cycle_state)
581+
if ((flags & TRB_CYCLE) != cycle_state) {
582+
/*
583+
* Give some extra time to get chance controller
584+
* to finish command before returning error code.
585+
* Checking CMD_RING_BUSY is not sufficient because
586+
* this bit is cleared to '0' when the Command
587+
* Descriptor has been executed by controller
588+
* and not when command completion event has
589+
* be added to event ring.
590+
*/
591+
if (retry--) {
592+
udelay(20);
593+
continue;
594+
}
595+
581596
return -EINVAL;
597+
}
582598

583599
cmd_dma = le64_to_cpu(event->event_cmd.cmd_trb);
584600

0 commit comments

Comments
 (0)