From 7037fd0e8d795c249298058818225812df54aaae Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Sat, 2 Aug 2025 20:52:25 +0800 Subject: [PATCH] update(port/dwc2/usb_hc_dwc2): only clean & invalid buffer in usbh_submit_urb, do not clean&invalid many times Signed-off-by: sakumisu <1203593632@qq.com> --- port/dwc2/usb_hc_dwc2.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c index eda503bc..8794593b 100644 --- a/port/dwc2/usb_hc_dwc2.c +++ b/port/dwc2/usb_hc_dwc2.c @@ -311,16 +311,6 @@ static inline void dwc2_chan_transfer(struct usbh_bus *bus, uint8_t ch_num, uint (((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) | (((uint32_t)pid << 29) & USB_OTG_HCTSIZ_DPID); - if (!(ep_addr & 0x80)) { - if (buf) { - usb_dcache_clean((uintptr_t)buf, USB_ALIGN_UP(size, CONFIG_USB_ALIGN_SIZE)); - } - } else { - if (buf) { - usb_dcache_invalidate((uintptr_t)buf, USB_ALIGN_UP(size, CONFIG_USB_ALIGN_SIZE)); - } - } - /* xfer_buff MUST be 32-bits aligned */ USB_OTG_HC(ch_num)->HCDMA = (uint32_t)buf; @@ -1066,6 +1056,25 @@ int usbh_submit_urb(struct usbh_urb *urb) usb_osal_leave_critical_section(flags); + if (urb->setup) { + usb_dcache_clean((uintptr_t)urb->setup, USB_ALIGN_UP(sizeof(struct usb_setup_packet), CONFIG_USB_ALIGN_SIZE)); + + if (urb->transfer_buffer) { + if (urb->setup->bmRequestType & 0x80) { + usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE)); + } else { + usb_dcache_clean((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE)); + } + } + } else if (urb->transfer_buffer && (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS)) { + if (urb->ep->bEndpointAddress & 0x80) { + usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE)); + } else { + usb_dcache_clean((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE)); + } + } else { + } + switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) { case USB_ENDPOINT_TYPE_CONTROL: chan->ep0_state = DWC2_EP0_STATE_SETUP;