From: John Youn Date: Fri, 20 May 2016 00:26:12 +0000 (-0700) Subject: UPSTREAM: usb: dwc3: gadget: Account for max size in TRB space X-Git-Tag: firefly_0821_release~1802 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1b10886a49d66a39bd9148ab7620fb36601883b3;p=firefly-linux-kernel-4.4.55.git UPSTREAM: usb: dwc3: gadget: Account for max size in TRB space The current calculation takes dep->trb_dequeue - dep->trb_enqueue to find the TRB space left. If you enqueue 1, that results in: (u8) 0 - (u8) 1 = 0xff = 255 TRBs left. This is correct if DWC3_TRB_NUM == 256. If DWC3_TRB_NUM is less than 256 (but still a power of 2) you need to mod the result by DWC3_TRB_NUM. For example the same calculation with DWC3_TRB_NUM = 8, results in: 255 % 6 = 7 TRBs left. Change-Id: I2b41bf750e767fc7062a72da054d581c56d42f5a Signed-off-by: John Youn Signed-off-by: Felipe Balbi Signed-off-by: Wu Liang feng (cherry picked from commit 32db3d9437b6bd560daeef82a8325436a4ac3366) --- diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a93b42973b97..09f61997b657 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -845,6 +845,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) { struct dwc3_trb *tmp; + u8 trbs_left; /* * If enqueue & dequeue are equal than it is either full or empty. @@ -864,7 +865,10 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) return DWC3_TRB_NUM - 1; } - return dep->trb_dequeue - dep->trb_enqueue; + trbs_left = dep->trb_dequeue - dep->trb_enqueue; + trbs_left %= DWC3_TRB_NUM; + + return trbs_left; } static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,