usb: dwc3: gadget: Set IOC if not enough for extra TRBs
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Thu, 24 Sep 2020 08:22:01 +0000 (01:22 -0700)
committerFelipe Balbi <balbi@kernel.org>
Fri, 2 Oct 2020 06:57:44 +0000 (09:57 +0300)
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>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
drivers/usb/dwc3/gadget.c

index ec142724e85c50dd8fa72840ae138e0806841c68..f091e107d9cbdc17a2f6fd03c6ae9107a1014d65 100644 (file)
@@ -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;
 }