]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
usb: dwc3: allocate setup_buf with dma_alloc_coherent()
authorNeil Armstrong <neil.armstrong@linaro.org>
Fri, 11 Oct 2024 14:38:24 +0000 (16:38 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 21 Oct 2024 21:27:33 +0000 (15:27 -0600)
Since setup_buf is also consumed by hardware DMA, aligns it's
allocation like other hardware buffers by introduce setup_buf_addr
populated by dma_alloc_coherent(), and use it to pass the physical
address of the buffer to the hardware.

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
drivers/usb/dwc3/core.h
drivers/usb/dwc3/ep0.c
drivers/usb/dwc3/gadget.c

index 7374ce950da8bdb27df0c7c45277938ea2ad4204..b572ea340c8c0951178df6cdf046131304ac0cd4 100644 (file)
@@ -670,6 +670,7 @@ struct dwc3_scratchpad_array {
  * @ep0_trb: dma address of ep0_trb
  * @ep0_usb_req: dummy req used while handling STD USB requests
  * @ep0_bounce_addr: dma address of ep0_bounce
+ * @setup_buf_addr: dma address of setup_buf
  * @scratch_addr: dma address of scratchbuf
  * @lock: for synchronizing
  * @dev: pointer to our struct device
@@ -757,6 +758,7 @@ struct dwc3 {
        dma_addr_t              ep0_trb_addr;
        dma_addr_t              ep0_bounce_addr;
        dma_addr_t              scratch_addr;
+       dma_addr_t              setup_buf_addr;
        struct dwc3_request     ep0_usb_req;
 
        /* device lock */
index 24f516a131b7632affea8a41137cefaee65bfc5a..8ba5fcd5312cdcb39d3fc3bea3272e1eab06e7c2 100644 (file)
@@ -380,7 +380,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
        dep = dwc->eps[0];
        dwc->ep0_usb_req.dep = dep;
        dwc->ep0_usb_req.request.length = sizeof(*response_pkt);
-       dwc->ep0_usb_req.request.buf = dwc->setup_buf;
+       dwc->ep0_usb_req.request.buf = (void *)dwc->setup_buf_addr;
        dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl;
 
        return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
@@ -662,7 +662,7 @@ static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
        dep = dwc->eps[0];
        dwc->ep0_usb_req.dep = dep;
        dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket;
-       dwc->ep0_usb_req.request.buf = dwc->setup_buf;
+       dwc->ep0_usb_req.request.buf = (void *)dwc->setup_buf_addr;
        dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl;
 
        return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
index fe33e307d3e59bc97d338b1602920cfa7553e617..19c3a5f5e58f05081d5bf71be4c095e4508743a4 100644 (file)
@@ -2653,8 +2653,8 @@ int dwc3_gadget_init(struct dwc3 *dwc)
                goto err1;
        }
 
-       dwc->setup_buf = memalign(CONFIG_SYS_CACHELINE_SIZE,
-                                 DWC3_EP0_BOUNCE_SIZE);
+       dwc->setup_buf = dma_alloc_coherent(DWC3_EP0_BOUNCE_SIZE,
+                                       (unsigned long *)&dwc->setup_buf_addr);
        if (!dwc->setup_buf) {
                ret = -ENOMEM;
                goto err2;
@@ -2701,7 +2701,7 @@ err4:
        dma_free_coherent(dwc->ep0_bounce);
 
 err3:
-       kfree(dwc->setup_buf);
+       dma_free_coherent(dwc->setup_buf);
 
 err2:
        dma_free_coherent(dwc->ep0_trb);
@@ -2723,7 +2723,7 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 
        dma_free_coherent(dwc->ep0_bounce);
 
-       kfree(dwc->setup_buf);
+       dma_free_coherent(dwc->setup_buf);
 
        dma_free_coherent(dwc->ep0_trb);