summaryrefslogtreecommitdiff
path: root/drivers/usb/dwc3
diff options
context:
space:
mode:
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>2020-09-24 01:21:49 -0700
committerFelipe Balbi <balbi@kernel.org>2020-10-02 09:57:44 +0300
commit13111fcb0d64fb69bd7466d6e2ca6ed7b95a9d50 (patch)
tree7adee0069b2fd4a6261b35722f1a88097f97abd7 /drivers/usb/dwc3
parent66706077dc89c66a4777a4c6298273816afb848c (diff)
usb: dwc3: gadget: Return the number of prepared TRBs
In preparation for fixing the check for number of remaining TRBs, revise dwc3_prepare_one_trb_linear() and dwc3_prepare_one_trb_sg() to return the number of prepared TRBs. Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Signed-off-by: Felipe Balbi <balbi@kernel.org>
Diffstat (limited to 'drivers/usb/dwc3')
-rw-r--r--drivers/usb/dwc3/gadget.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 97790f55be1a..673a34b715e2 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1094,7 +1094,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
stream_id, short_not_ok, no_interrupt, is_last);
}
-static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
+static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
struct dwc3_request *req)
{
struct scatterlist *sg = req->start_sg;
@@ -1105,6 +1105,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
unsigned int rem = length % maxp;
unsigned int remaining = req->request.num_mapped_sgs
- req->num_queued_sgs;
+ unsigned int num_trbs = req->num_trbs;
/*
* If we resume preparing the request, then get the remaining length of
@@ -1131,9 +1132,15 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
if ((i == remaining - 1) || !length)
chain = false;
+ if (!dwc3_calc_trbs_left(dep))
+ break;
+
if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) {
/* prepare normal TRB */
if (req->request.length) {
+ if (dwc3_calc_trbs_left(dep) < 2)
+ goto out;
+
req->needs_extra_trb = true;
dwc3_prepare_one_trb(dep, req, trb_length,
true, i, false);
@@ -1145,6 +1152,10 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
} else if (req->request.zero && req->request.length &&
!usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
!rem && !chain) {
+
+ if (dwc3_calc_trbs_left(dep) < 2)
+ goto out;
+
req->needs_extra_trb = true;
/* Prepare normal TRB */
@@ -1185,18 +1196,28 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
if (!dwc3_calc_trbs_left(dep))
break;
}
+
+out:
+ return req->num_trbs - num_trbs;
}
-static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
+static int dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
struct dwc3_request *req)
{
unsigned int length = req->request.length;
unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
unsigned int rem = length % maxp;
+ unsigned int num_trbs = req->num_trbs;
+
+ if (!dwc3_calc_trbs_left(dep))
+ goto out;
if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) {
/* prepare normal TRB */
if (req->request.length) {
+ if (dwc3_calc_trbs_left(dep) < 2)
+ goto out;
+
req->needs_extra_trb = true;
dwc3_prepare_one_trb(dep, req, length, true, 0, false);
}
@@ -1206,6 +1227,10 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
} else if (req->request.zero && req->request.length &&
!usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
(IS_ALIGNED(req->request.length, maxp))) {
+
+ if (dwc3_calc_trbs_left(dep) < 2)
+ goto out;
+
req->needs_extra_trb = true;
/* prepare normal TRB */
@@ -1215,8 +1240,14 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
dwc3_prepare_one_trb(dep, req, req->direction ? 0 : maxp,
false, 1, true);
} else {
+ if (!dwc3_calc_trbs_left(dep))
+ goto out;
+
dwc3_prepare_one_trb(dep, req, length, false, 0, false);
}
+
+out:
+ return req->num_trbs - num_trbs;
}
/*