UPSTREAM: usb: dwc3: gadget: Account for max size in TRB space
authorJohn Youn <johnyoun@synopsys.com>
Fri, 20 May 2016 00:26:12 +0000 (17:26 -0700)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 16 Aug 2016 12:48:19 +0000 (20:48 +0800)
commit1b10886a49d66a39bd9148ab7620fb36601883b3
tree851e5068ecfd49e4250dfd9d08a20308e2857f1a
parentf906253bf08ba2aafbc0f6e907c580473e923bb2
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 <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
(cherry picked from commit 32db3d9437b6bd560daeef82a8325436a4ac3366)
drivers/usb/dwc3/gadget.c