Skip to content

Commit c423357

Browse files
author
Felipe Balbi
committed
usb: dwc3: gadget: prepare TRBs on update transfers too
If we're updating transfers, we can also prepare as many TRBs as we can fit in the ring. Let's start doing that. This patch 'solves' a limitation of how many TRBs we can prepare when we're getting close the end of the ring. Instead driver to prepare only up to end of the ring, we check if we have space to wrap around the ring properly. Note that this only happens when our enqueue and dequeue pointers are equal (which is the case for bulk endpoints after an XferComplete event). Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent 7f370ed commit c423357

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -880,40 +880,48 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
880880
trace_dwc3_prepare_trb(dep, trb);
881881
}
882882

883+
static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
884+
{
885+
struct dwc3_trb *tmp;
886+
887+
/*
888+
* If enqueue & dequeue are equal than it is either full or empty.
889+
*
890+
* One way to know for sure is if the TRB right before us has HWO bit
891+
* set or not. If it has, then we're definitely full and can't fit any
892+
* more transfers in our ring.
893+
*/
894+
if (dep->trb_enqueue == dep->trb_dequeue) {
895+
/* If we're full, enqueue/dequeue are > 0 */
896+
if (dep->trb_enqueue) {
897+
tmp = &dep->trb_pool[dep->trb_enqueue - 1];
898+
if (tmp->ctrl & DWC3_TRB_CTRL_HWO)
899+
return 0;
900+
}
901+
902+
return DWC3_TRB_NUM - 1;
903+
}
904+
905+
return dep->trb_dequeue - dep->trb_enqueue;
906+
}
907+
883908
/*
884909
* dwc3_prepare_trbs - setup TRBs from requests
885910
* @dep: endpoint for which requests are being prepared
886-
* @starting: true if the endpoint is idle and no requests are queued.
887911
*
888912
* The function goes through the requests list and sets up TRBs for the
889913
* transfers. The function returns once there are no more TRBs available or
890914
* it runs out of requests.
891915
*/
892-
static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting)
916+
static void dwc3_prepare_trbs(struct dwc3_ep *dep)
893917
{
894918
struct dwc3_request *req, *n;
895919
u32 trbs_left;
896920
unsigned int last_one = 0;
897921

898922
BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM);
899923

900-
trbs_left = dep->trb_dequeue - dep->trb_enqueue;
901-
902-
/*
903-
* If enqueue & dequeue are equal than it is either full or empty. If we
904-
* are starting to process requests then we are empty. Otherwise we are
905-
* full and don't do anything
906-
*/
907-
if (!trbs_left) {
908-
if (!starting)
909-
return;
910-
911-
trbs_left = DWC3_TRB_NUM;
912-
}
913-
914-
/* The last TRB is a link TRB, not used for xfer */
915-
if (trbs_left <= 1)
916-
return;
924+
trbs_left = dwc3_calc_trbs_left(dep);
917925

918926
list_for_each_entry_safe(req, n, &dep->pending_list, list) {
919927
unsigned length;
@@ -996,12 +1004,12 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param,
9961004
*/
9971005
if (start_new) {
9981006
if (list_empty(&dep->started_list))
999-
dwc3_prepare_trbs(dep, start_new);
1007+
dwc3_prepare_trbs(dep);
10001008

10011009
/* req points to the first request which will be sent */
10021010
req = next_request(&dep->started_list);
10031011
} else {
1004-
dwc3_prepare_trbs(dep, start_new);
1012+
dwc3_prepare_trbs(dep);
10051013

10061014
/*
10071015
* req points to the first request where HWO changed from 0 to 1

0 commit comments

Comments
 (0)