diff mbox series

[2/4] usb: dwc3: gadget: Revise setting IOC when no TRB left

Message ID 91107f27d4d8bd3514eb2bafb46ac7905e276644.1601511883.git.Thinh.Nguyen@synopsys.com (mailing list archive)
State Accepted
Commit 8dbbe48c7a9989c75e39bfb2a886e163fa21660a
Headers show
Series usb: dwc3: gadget: More TRB handling cleanup | expand

Commit Message

Thinh Nguyen Oct. 1, 2020, 12:44 a.m. UTC
To keep the setting of interrupt-on-completion (IOC) when out of TRBs
consistent and easier to read, the caller of dwc3_prepare_one_trb()
will determine if the TRB must have IOC bit set. This also reduces the
number of times we need to call dwc3_calc_trbs_left(). Note that we only
care about setting IOC from insufficient number of TRBs for SG and not
linear requests (because we don't need to split linear requests).

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

Patch

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0387b94b8f94..327cd556e8db 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1034,8 +1034,7 @@  static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb,
 			trb->ctrl |= DWC3_TRB_CTRL_ISP_IMI;
 	}
 
-	if ((!no_interrupt && !chain) || must_interrupt ||
-			(dwc3_calc_trbs_left(dep) == 1))
+	if ((!no_interrupt && !chain) || must_interrupt)
 		trb->ctrl |= DWC3_TRB_CTRL_IOC;
 
 	if (chain)
@@ -1169,6 +1168,7 @@  static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
 		length -= sg_dma_len(s);
 
 	for_each_sg(sg, s, remaining, i) {
+		unsigned int num_trbs_left = dwc3_calc_trbs_left(dep);
 		unsigned int trb_length;
 		bool must_interrupt = false;
 		bool last_sg = false;
@@ -1187,7 +1187,7 @@  static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
 		if ((i == remaining - 1) || !length)
 			last_sg = true;
 
-		if (!dwc3_calc_trbs_left(dep))
+		if (!num_trbs_left)
 			break;
 
 		if (last_sg) {
@@ -1196,12 +1196,13 @@  static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
 		} else {
 			/*
 			 * Look ahead to check if we have enough TRBs for the
-			 * last SG entry. If not, set interrupt on this TRB to
-			 * resume preparing the last SG entry when more TRBs are
+			 * next SG entry. If not, set interrupt on this TRB to
+			 * resume preparing the next SG entry when more TRBs are
 			 * free.
 			 */
-			if (needs_extra_trb && dwc3_calc_trbs_left(dep) <= 2 &&
-					sg_dma_len(sg_next(s)) >= length)
+			if (num_trbs_left == 1 || (needs_extra_trb &&
+					num_trbs_left <= 2 &&
+					sg_dma_len(sg_next(s)) >= length))
 				must_interrupt = true;
 
 			dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false,
@@ -1230,7 +1231,7 @@  static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
 			break;
 		}
 
-		if (!dwc3_calc_trbs_left(dep) || must_interrupt)
+		if (must_interrupt)
 			break;
 	}