Skip to content

Commit cf77b5f

Browse files
Vahram AharonyanFelipe Balbi
authored andcommitted
usb: dwc2: gadget: Transfer length limit checking for DDMA
Add dwc2_gadget_get_chain_limit() function and its call in transfer start routine to correctly estimate one go on transfer size if descriptor DMA mode is selected. Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com> Signed-off-by: John Youn <johnyoun@synopsys.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent 3a1ec35 commit cf77b5f

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

drivers/usb/dwc2/gadget.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,32 @@ static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg)
601601
return dsts;
602602
}
603603

604+
/**
605+
* dwc2_gadget_get_chain_limit - get the maximum data payload value of the
606+
* DMA descriptor chain prepared for specific endpoint
607+
* @hs_ep: The endpoint
608+
*
609+
* Return the maximum data that can be queued in one go on a given endpoint
610+
* depending on its descriptor chain capacity so that transfers that
611+
* are too long can be split.
612+
*/
613+
static unsigned int dwc2_gadget_get_chain_limit(struct dwc2_hsotg_ep *hs_ep)
614+
{
615+
int is_isoc = hs_ep->isochronous;
616+
unsigned int maxsize;
617+
618+
if (is_isoc)
619+
maxsize = hs_ep->dir_in ? DEV_DMA_ISOC_TX_NBYTES_LIMIT :
620+
DEV_DMA_ISOC_RX_NBYTES_LIMIT;
621+
else
622+
maxsize = DEV_DMA_NBYTES_LIMIT;
623+
624+
/* Above size of one descriptor was chosen, multiple it */
625+
maxsize *= MAX_DMA_DESC_NUM_GENERIC;
626+
627+
return maxsize;
628+
}
629+
604630
/**
605631
* dwc2_hsotg_start_req - start a USB request from an endpoint's queue
606632
* @hsotg: The controller state.
@@ -659,7 +685,11 @@ static void dwc2_hsotg_start_req(struct dwc2_hsotg *hsotg,
659685
dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n",
660686
ureq->length, ureq->actual);
661687

662-
maxreq = get_ep_limit(hs_ep);
688+
if (!using_desc_dma(hsotg))
689+
maxreq = get_ep_limit(hs_ep);
690+
else
691+
maxreq = dwc2_gadget_get_chain_limit(hs_ep);
692+
663693
if (length > maxreq) {
664694
int round = maxreq % hs_ep->ep.maxpacket;
665695

0 commit comments

Comments
 (0)