From 605f270f988e23fd0f6a6b0e109ffce6cfe922a1 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 14 Jun 2022 18:41:33 +0300 Subject: [PATCH] bdk: usb: fix a race condition in USB2 stack When RAM is slow (no training), it's possible to have the stack failing to negotiate configuration successfully. The race condition is caused by not flushing cache before sending a configuration packet reply. Although, cache is write-through, this needs to happen. --- bdk/usb/usbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bdk/usb/usbd.c b/bdk/usb/usbd.c index 223cfa7..8332d09 100644 --- a/bdk/usb/usbd.c +++ b/bdk/usb/usbd.c @@ -785,13 +785,13 @@ static int _usbd_ep_operation(usb_ep_t endpoint, u8 *buf, u32 len, u32 sync_time AHB_GIZMO(AHB_AHB_MEM_PREFETCH_CFG1) |= MEM_PREFETCH_ENABLE; if (direction == USB_DIR_IN) - { prime_bit = USB2D_ENDPT_STATUS_TX_OFFSET << actual_ep; - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); - } else prime_bit = USB2D_ENDPT_STATUS_RX_OFFSET << actual_ep; + // Flush data before priming EP. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); + // Prime endpoint. usbd_otg->regs->endptprime |= prime_bit; // USB2_CONTROLLER_USB2D_ENDPTPRIME.