usb: dwc3: gadget: track number of TRBs per request
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Fri, 28 Jun 2019 18:24:07 +0000 (18:24 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jul 2019 11:14:43 +0000 (13:14 +0200)
commit 09fe1f8d7e2f461275b1cdd832f2cfa5e9be346d upstream

This will help us remove the wait_event() from our ->dequeue().

Cc: Fei Yang <fei.yang@intel.com>
Cc: Sam Protsenko <semen.protsenko@linaro.org>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: linux-usb@vger.kernel.org
Cc: stable@vger.kernel.org # 4.19.y
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
(cherry picked from commit 09fe1f8d7e2f461275b1cdd832f2cfa5e9be346d)
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/dwc3/core.h
drivers/usb/dwc3/gadget.c

index 4872cba8699b49567404d670bf00ccd5c16743b0..0de78cb29f2cb87478be516709dcd5f7e4467d0f 100644 (file)
@@ -847,6 +847,7 @@ struct dwc3_hwparams {
  * @epnum: endpoint number to which this request refers
  * @trb: pointer to struct dwc3_trb
  * @trb_dma: DMA address of @trb
+ * @num_trbs: number of TRBs used by this request
  * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP
  *     or unaligned OUT)
  * @direction: IN or OUT direction flag
@@ -867,6 +868,8 @@ struct dwc3_request {
        struct dwc3_trb         *trb;
        dma_addr_t              trb_dma;
 
+       unsigned                num_trbs;
+
        unsigned                needs_extra_trb:1;
        unsigned                direction:1;
        unsigned                mapped:1;
index 8db7466e4f767d92624641e7196bda8968c02faf..fd91c494307c9efd9bb19ab24a972fba4638802d 100644 (file)
@@ -1041,6 +1041,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
                req->trb_dma = dwc3_trb_dma_offset(dep, trb);
        }
 
+       req->num_trbs++;
+
        __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node,
                        stream_id, short_not_ok, no_interrupt);
 }
@@ -1075,6 +1077,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
 
                        /* Now prepare one extra TRB to align transfer size */
                        trb = &dep->trb_pool[dep->trb_enqueue];
+                       req->num_trbs++;
                        __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr,
                                        maxp - rem, false, 1,
                                        req->request.stream_id,
@@ -1119,6 +1122,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
 
                /* Now prepare one extra TRB to align transfer size */
                trb = &dep->trb_pool[dep->trb_enqueue];
+               req->num_trbs++;
                __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem,
                                false, 1, req->request.stream_id,
                                req->request.short_not_ok,
@@ -1135,6 +1139,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
 
                /* Now prepare one extra TRB to handle ZLP */
                trb = &dep->trb_pool[dep->trb_enqueue];
+               req->num_trbs++;
                __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0,
                                false, 1, req->request.stream_id,
                                req->request.short_not_ok,
@@ -2231,6 +2236,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,
        dwc3_ep_inc_deq(dep);
 
        trace_dwc3_complete_trb(dep, trb);
+       req->num_trbs--;
 
        /*
         * If we're in the middle of series of chained TRBs and we