diff mbox series

[08/10] usb: dwc3: gadget: Set IOC if not enough for extra TRBs

Message ID bbc364093decd1806a021f0548313ec103230a39.1600935293.git.Thinh.Nguyen@synopsys.com
State New
Headers show
Series usb: dwc3: gadget: Revise preparation for extra TRBs | expand

Commit Message

Thinh Nguyen Sept. 24, 2020, 8:22 a.m. UTC
If we run out of TRBs because we need extra TRBs, make sure to set the
IOC bit for the previously prepared TRB to get completion notification
to free up TRBs to resume later.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
 drivers/usb/dwc3/gadget.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f43421246f89..840d6e49f668 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1197,7 +1197,27 @@  static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
 			break;
 	}
 
+	return req->num_trbs - num_trbs;
+
 out:
+	/*
+	 * If we run out of TRBs for MPS alignment setup, then set IOC on the
+	 * previous TRB to get notified for TRB completion to resume when more
+	 * TRBs are available.
+	 *
+	 * Note: normally we shouldn't update the TRB after the HWO bit is set.
+	 * However, the controller doesn't update its internal cache to handle
+	 * the newly prepared TRBs until UPDATE_TRANSFER or START_TRANSFER
+	 * command is executed. At this point, it doesn't happen yet, so we
+	 * should be fine modifying it here.
+	 */
+	if (i) {
+		struct dwc3_trb	*trb;
+
+		trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue);
+		trb->ctrl |= DWC3_TRB_CTRL_IOC;
+	}
+
 	return req->num_trbs - num_trbs;
 }