MLK-18319-1 usb: cdns3: gadget: improvement the handling for non-aligned buffer
If the user buffer is not 8-byte aligned, it needs to use debounce buffer for DMA transfer, and in this commit, we do below two improvements: - Copy back the request buffer when the transfer has completed - Using Macro for default debounce buffer size Reviewed-by: Li Jun <jun.li@nxp.com> Signed-off-by: Peter Chen <peter.chen@nxp.com>pull/10/head
parent
ff04375ae8
commit
65aed0a45f
|
@ -414,9 +414,14 @@ static int cdns_ep_run_transfer(struct usb_ss_endpoint *usb_ss_ep)
|
|||
trb_dma = request->dma;
|
||||
|
||||
/* must allocate buffer aligned to 8 */
|
||||
if (request->dma % ADDR_MODULO_8) {
|
||||
memcpy(usb_ss_ep->cpu_addr, request->buf, request->length);
|
||||
trb_dma = usb_ss_ep->dma_addr;
|
||||
if ((request->dma % ADDR_MODULO_8)) {
|
||||
if (request->length <= CDNS3_UNALIGNED_BUF_SIZE) {
|
||||
memcpy(usb_ss_ep->cpu_addr, request->buf,
|
||||
request->length);
|
||||
trb_dma = usb_ss_ep->dma_addr;
|
||||
} else {
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
trb = usb_ss_ep->trb_pool;
|
||||
|
@ -1006,6 +1011,11 @@ static int cdns_check_ep_interrupt_proceed(struct usb_ss_endpoint *usb_ss_ep)
|
|||
if (!request)
|
||||
return 0;
|
||||
|
||||
if ((request->dma % ADDR_MODULO_8) &&
|
||||
(usb_ss_ep->dir == USB_DIR_OUT))
|
||||
memcpy(request->buf, usb_ss_ep->cpu_addr,
|
||||
request->length);
|
||||
|
||||
usb_gadget_unmap_request_by_dev(usb_ss->sysdev, request,
|
||||
usb_ss_ep->endpoint.desc->bEndpointAddress
|
||||
& ENDPOINT_DIR_MASK);
|
||||
|
@ -1605,9 +1615,9 @@ static int usb_ss_gadget_ep_enable(struct usb_ep *ep,
|
|||
return ret;
|
||||
|
||||
if (!usb_ss_ep->cpu_addr) {
|
||||
usb_ss_ep->cpu_addr = dma_alloc_coherent(usb_ss->sysdev, 4096,
|
||||
&usb_ss_ep->dma_addr, GFP_DMA);
|
||||
|
||||
usb_ss_ep->cpu_addr = dma_alloc_coherent(usb_ss->sysdev,
|
||||
CDNS3_UNALIGNED_BUF_SIZE,
|
||||
&usb_ss_ep->dma_addr, GFP_DMA);
|
||||
if (!usb_ss_ep->cpu_addr)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -1711,8 +1721,8 @@ static void usb_ss_free_trb_pool(struct usb_ss_endpoint *usb_ss_ep)
|
|||
}
|
||||
|
||||
if (usb_ss_ep->cpu_addr) {
|
||||
dma_free_coherent(usb_ss->sysdev, 4096, usb_ss_ep->cpu_addr,
|
||||
usb_ss_ep->dma_addr);
|
||||
dma_free_coherent(usb_ss->sysdev, CDNS3_UNALIGNED_BUF_SIZE,
|
||||
usb_ss_ep->cpu_addr, usb_ss_ep->dma_addr);
|
||||
usb_ss_ep->cpu_addr = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1853,7 +1863,7 @@ static int usb_ss_gadget_ep_queue(struct usb_ep *ep,
|
|||
|
||||
if (empty_list) {
|
||||
if (!usb_ss_ep->stalled_flag)
|
||||
cdns_ep_run_transfer(usb_ss_ep);
|
||||
ret = cdns_ep_run_transfer(usb_ss_ep);
|
||||
}
|
||||
spin_unlock_irqrestore(&usb_ss->lock, flags);
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
/* 18KB is the total size, and 2KB is used for EP0 and configuration */
|
||||
#define CDNS3_ONCHIP_BUF_SIZE 16 /* KB */
|
||||
#define CDNS3_EP_BUF_SIZE 2 /* KB */
|
||||
#define CDNS3_UNALIGNED_BUF_SIZE 16384 /* Bytes */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* Used structs */
|
||||
|
||||
|
|
Loading…
Reference in New Issue