usb: dwc3: gadget: Fix TRB pointer increment logic
Currently the driver assumes that the number of TRBs per EP would
be 256 (DWC3_TRB_NUM) and accordingly goes back to 0th TRB if
pointer reaches 255th index (link TRB). But the GSI EPs can have
lesser number of TRBs, say 16. And if it uses SW interrupt, then
the TRB pointer increment logic fails because TRB from index 16
to 254 is invalid.
Fix this by checking index against dep->num_trbs which is
programmed separately for normal and GSI EPs.
Change-Id: Ida5745c2d7d0564507333c5b38d728090e70fcf6
Signed-off-by: Ajay Agarwal <ajaya@codeaurora.org>
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8438999..ac5b101 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -152,27 +152,28 @@
/**
* dwc3_ep_inc_trb() - Increment a TRB index.
+ * @dep - DWC3 endpoint
* @index - Pointer to the TRB index to increment.
*
* The index should never point to the link TRB. After incrementing,
* if it is point to the link TRB, wrap around to the beginning. The
* link TRB is always at the last TRB entry.
*/
-static void dwc3_ep_inc_trb(u8 *index)
+static void dwc3_ep_inc_trb(struct dwc3_ep *dep, u8 *index)
{
(*index)++;
- if (*index == (DWC3_TRB_NUM - 1))
+ if (*index == (dep->num_trbs - 1))
*index = 0;
}
void dwc3_ep_inc_enq(struct dwc3_ep *dep)
{
- dwc3_ep_inc_trb(&dep->trb_enqueue);
+ dwc3_ep_inc_trb(dep, &dep->trb_enqueue);
}
void dwc3_ep_inc_deq(struct dwc3_ep *dep)
{
- dwc3_ep_inc_trb(&dep->trb_dequeue);
+ dwc3_ep_inc_trb(dep, &dep->trb_dequeue);
}
/*
@@ -2736,14 +2737,14 @@
trb = &dep->trb_pool[dep->trb_dequeue];
while (trb->ctrl & DWC3_TRBCTL_LINK_TRB) {
- dwc3_ep_inc_trb(&dep->trb_dequeue);
+ dwc3_ep_inc_trb(dep, &dep->trb_dequeue);
trb = &dep->trb_pool[dep->trb_dequeue];
}
if (!(trb->ctrl & DWC3_TRB_CTRL_HWO)) {
offset = dwc3_trb_dma_offset(dep, trb);
usb_gsi_ep_op(ep, (void *)&offset, GSI_EP_OP_UPDATE_DB);
- dwc3_ep_inc_trb(&dep->trb_dequeue);
+ dwc3_ep_inc_trb(dep, &dep->trb_dequeue);
}
}