There are a few issues in DWC3 driver when preparing for TRB. The driver needs to account the following:
* MPS alignment for ZLP OUT direction * Extra TRBs when checking for available TRBs * SG entries size > request length
Along with these fixes, there are some cleanup/refactoring patches in this series.
Changes in v2: - Update remaining length when resume request - Remove unused variables - Add a missing "return 0" for dwc3_prepare_trbs() - Update doc indicating dwc3_prepare_trbs() can return other -errno
Thinh Nguyen (7): usb: dwc3: gadget: Don't setup more than requested usb: dwc3: gadget: Fix handling ZLP usb: dwc3: gadget: Handle ZLP for sg requests usb: dwc3: gadget: Refactor preparing TRBs usb: dwc3: gadget: Account for extra TRB usb: dwc3: gadget: Rename misleading function names usb: dwc3: ep0: Skip ZLP setup for OUT
drivers/usb/dwc3/ep0.c | 2 +- drivers/usb/dwc3/gadget.c | 247 +++++++++++++++++++++++--------------- 2 files changed, 148 insertions(+), 101 deletions(-)
base-commit: e3ee0e740c3887d2293e8d54a8707218d70d86ca
The SG list may be set up with entry size more than the requested length. Check the usb_request->length and make sure that we don't setup the TRBs to send/receive more than requested. This case may occur when the SG entry is allocated up to a certain minimum size, but the request length is less than that. It can also occur when the request is reused for a different request length.
Cc: stable@vger.kernel.org Fixes: a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists") Signed-off-by: Thinh Nguyen thinhn@synopsys.com --- Changes in v2: - Update remaining length when resume request
drivers/usb/dwc3/gadget.c | 51 +++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e44bfc3b5096..f9231253cbed 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1054,27 +1054,25 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, * dwc3_prepare_one_trb - setup one TRB from one request * @dep: endpoint for which this request is prepared * @req: dwc3_request pointer + * @trb_length: buffer size of the TRB * @chain: should this TRB be chained to the next? * @node: only for isochronous endpoints. First TRB needs different type. */ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, - struct dwc3_request *req, unsigned chain, unsigned node) + struct dwc3_request *req, unsigned int trb_length, + unsigned chain, unsigned node) { struct dwc3_trb *trb; - unsigned int length; dma_addr_t dma; unsigned stream_id = req->request.stream_id; unsigned short_not_ok = req->request.short_not_ok; unsigned no_interrupt = req->request.no_interrupt; unsigned is_last = req->request.is_last;
- if (req->request.num_sgs > 0) { - length = sg_dma_len(req->start_sg); + if (req->request.num_sgs > 0) dma = sg_dma_address(req->start_sg); - } else { - length = req->request.length; + else dma = req->request.dma; - }
trb = &dep->trb_pool[dep->trb_enqueue];
@@ -1086,7 +1084,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
req->num_trbs++;
- __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node, + __dwc3_prepare_one_trb(dep, trb, dma, trb_length, chain, node, stream_id, short_not_ok, no_interrupt, is_last); }
@@ -1096,16 +1094,27 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct scatterlist *sg = req->start_sg; struct scatterlist *s; int i; - + unsigned int length = req->request.length; unsigned int remaining = req->request.num_mapped_sgs - req->num_queued_sgs;
+ /* + * If we resume preparing the request, then get the remaining length of + * the request and resume where we left off. + */ + for_each_sg(req->request.sg, s, req->num_queued_sgs, i) + length -= sg_dma_len(s); + for_each_sg(sg, s, remaining, i) { - unsigned int length = req->request.length; unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); unsigned int rem = length % maxp; + unsigned int trb_length; unsigned chain = true;
+ trb_length = min_t(unsigned int, length, sg_dma_len(s)); + + length -= trb_length; + /* * IOMMU driver is coalescing the list of sgs which shares a * page boundary into one and giving it to USB driver. With @@ -1113,7 +1122,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, * sgs passed. So mark the chain bit to false if it isthe last * mapped sg. */ - if (i == remaining - 1) + if ((i == remaining - 1) || !length) chain = false;
if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { @@ -1123,7 +1132,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, req->needs_extra_trb = true;
/* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, true, i); + dwc3_prepare_one_trb(dep, req, trb_length, true, i);
/* Now prepare one extra TRB to align transfer size */ trb = &dep->trb_pool[dep->trb_enqueue]; @@ -1135,7 +1144,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, req->request.no_interrupt, req->request.is_last); } else { - dwc3_prepare_one_trb(dep, req, chain, i); + dwc3_prepare_one_trb(dep, req, trb_length, chain, i); }
/* @@ -1150,6 +1159,16 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
req->num_queued_sgs++;
+ /* + * The number of pending SG entries may not correspond to the + * number of mapped SG entries. If all the data are queued, then + * don't include unused SG entries. + */ + if (length == 0) { + req->num_pending_sgs -= req->request.num_mapped_sgs - req->num_queued_sgs; + break; + } + if (!dwc3_calc_trbs_left(dep)) break; } @@ -1169,7 +1188,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, req->needs_extra_trb = true;
/* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, true, 0); + dwc3_prepare_one_trb(dep, req, length, true, 0);
/* Now prepare one extra TRB to align transfer size */ trb = &dep->trb_pool[dep->trb_enqueue]; @@ -1187,7 +1206,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, req->needs_extra_trb = true;
/* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, true, 0); + dwc3_prepare_one_trb(dep, req, length, true, 0);
/* Now prepare one extra TRB to handle ZLP */ trb = &dep->trb_pool[dep->trb_enqueue]; @@ -1198,7 +1217,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, req->request.no_interrupt, req->request.is_last); } else { - dwc3_prepare_one_trb(dep, req, false, 0); + dwc3_prepare_one_trb(dep, req, length, false, 0); } }
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists").
The bot has tested the following trees: v5.8, v5.7.14, v5.4.57, v4.19.138.
v5.8: Build OK! v5.7.14: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v5.4.57: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v4.19.138: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 974a1368c33e ("usb: dwc3: gadget: don't use resource_index as a flag") a3af5e3ad3f1 ("usb: dwc3: gadget: add dwc3_request status tracking") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") c58d8bfc77a2 ("usb: dwc3: gadget: Check END_TRANSFER completion") d3abda5a98a1 ("usb: dwc3: gadget: Clear started flag for non-IOC") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests") da10bcdd6f70 ("usb: dwc3: gadget: Delay starting transfer")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists").
The bot has tested the following trees: v5.8.1, v5.7.15, v5.4.58, v4.19.139.
v5.8.1: Build OK! v5.7.15: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v5.4.58: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v4.19.139: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 974a1368c33e ("usb: dwc3: gadget: don't use resource_index as a flag") a3af5e3ad3f1 ("usb: dwc3: gadget: add dwc3_request status tracking") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") c58d8bfc77a2 ("usb: dwc3: gadget: Check END_TRANSFER completion") d3abda5a98a1 ("usb: dwc3: gadget: Clear started flag for non-IOC") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests") da10bcdd6f70 ("usb: dwc3: gadget: Delay starting transfer")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists").
The bot has tested the following trees: v5.8.2, v5.7.16, v5.4.59, v4.19.140.
v5.8.2: Build OK! v5.7.16: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v5.4.59: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v4.19.140: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 974a1368c33e ("usb: dwc3: gadget: don't use resource_index as a flag") a3af5e3ad3f1 ("usb: dwc3: gadget: add dwc3_request status tracking") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") c58d8bfc77a2 ("usb: dwc3: gadget: Check END_TRANSFER completion") d3abda5a98a1 ("usb: dwc3: gadget: Clear started flag for non-IOC") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests") da10bcdd6f70 ("usb: dwc3: gadget: Delay starting transfer")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
The usb_request->zero doesn't apply for isoc. Also, if we prepare a 0-length (ZLP) TRB for the OUT direction, we need to prepare an extra TRB to pad up to the MPS alignment. Use the same bounce buffer for the ZLP TRB and the extra pad TRB.
Cc: stable@vger.kernel.org Fixes: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling") Fixes: 04c03d10e507 ("usb: dwc3: gadget: handle request->zero") Signed-off-by: Thinh Nguyen thinhn@synopsys.com --- Changes in v2: - None
drivers/usb/dwc3/gadget.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f9231253cbed..df603a817a98 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1199,6 +1199,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, req->request.no_interrupt, req->request.is_last); } else if (req->request.zero && req->request.length && + !usb_endpoint_xfer_isoc(dep->endpoint.desc) && (IS_ALIGNED(req->request.length, maxp))) { struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; @@ -1208,14 +1209,25 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, /* prepare normal TRB */ dwc3_prepare_one_trb(dep, req, length, true, 0);
- /* Now prepare one extra TRB to handle ZLP */ + /* 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->direction, 1, req->request.stream_id, req->request.short_not_ok, req->request.no_interrupt, req->request.is_last); + + /* Prepare one more TRB to handle MPS alignment for OUT */ + if (!req->direction) { + trb = &dep->trb_pool[dep->trb_enqueue]; + req->num_trbs++; + __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, + false, 1, req->request.stream_id, + req->request.short_not_ok, + req->request.no_interrupt, + req->request.is_last); + } } else { dwc3_prepare_one_trb(dep, req, length, false, 0); } @@ -2690,8 +2702,17 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, status);
if (req->needs_extra_trb) { + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); + ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); + + /* Reclaim MPS padding TRB for ZLP */ + if (!req->direction && req->request.zero && req->request.length && + !usb_endpoint_xfer_isoc(dep->endpoint.desc) && + (IS_ALIGNED(req->request.length, maxp))) + ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); + req->needs_extra_trb = false; }
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling").
The bot has tested the following trees: v5.8.1, v5.7.15, v5.4.58, v4.19.139, v4.14.193.
v5.8.1: Build OK! v5.7.15: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v5.4.58: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v4.19.139: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 974a1368c33e ("usb: dwc3: gadget: don't use resource_index as a flag") a3af5e3ad3f1 ("usb: dwc3: gadget: add dwc3_request status tracking") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") c58d8bfc77a2 ("usb: dwc3: gadget: Check END_TRANSFER completion") d3abda5a98a1 ("usb: dwc3: gadget: Clear started flag for non-IOC") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests") da10bcdd6f70 ("usb: dwc3: gadget: Delay starting transfer")
v4.14.193: Failed to apply! Possible dependencies: 09fe1f8d7e2f ("usb: dwc3: gadget: track number of TRBs per request") 0bd0f6d201eb ("usb: dwc3: gadget: remove allocated/queued request tracking") 1a22ec643580 ("usb: dwc3: gadget: combine unaligned and zero flags") 38408464aa76 ("usb: dwc3: gadget: XferNotReady is Isoc-only") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 502a37b98a7b ("usb: dwc3: gadget: cache frame number in struct dwc3_ep") 66f5dd5a0379 ("usb: dwc3: gadget: rename done_trbs and done_reqs") 7fdca766499b ("usb: dwc3: gadget: simplify __dwc3_gadget_kick_transfer() prototype") 8f608e8ab628 ("usb: dwc3: gadget: remove unnecessary 'dwc' parameter") a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists") d80fe1b6e34d ("usb: dwc3: gadget: simplify short packet event") e0c42ce590fe ("usb: dwc3: gadget: simplify IOC handling") f38e35dd84e2 ("usb: dwc3: gadget: split dwc3_gadget_ep_cleanup_completed_requests()") fbea935accf4 ("usb: dwc3: gadget: rename dwc3_endpoint_transfer_complete()")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling").
The bot has tested the following trees: v5.8.2, v5.7.16, v5.4.59, v4.19.140, v4.14.193.
v5.8.2: Build OK! v5.7.16: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v5.4.59: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests")
v4.19.140: Failed to apply! Possible dependencies: 2e6e9e4b2ed7 ("usb: dwc3: gadget: Refactor TRB completion handler") 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 974a1368c33e ("usb: dwc3: gadget: don't use resource_index as a flag") a3af5e3ad3f1 ("usb: dwc3: gadget: add dwc3_request status tracking") b6842d4938c3 ("usb: dwc3: gadget: Check for in-progress END_TRANSFER") c58d8bfc77a2 ("usb: dwc3: gadget: Check END_TRANSFER completion") d3abda5a98a1 ("usb: dwc3: gadget: Clear started flag for non-IOC") d9feef974e0d ("usb: dwc3: gadget: Continue to process pending requests") da10bcdd6f70 ("usb: dwc3: gadget: Delay starting transfer")
v4.14.193: Failed to apply! Possible dependencies: 09fe1f8d7e2f ("usb: dwc3: gadget: track number of TRBs per request") 0bd0f6d201eb ("usb: dwc3: gadget: remove allocated/queued request tracking") 1a22ec643580 ("usb: dwc3: gadget: combine unaligned and zero flags") 38408464aa76 ("usb: dwc3: gadget: XferNotReady is Isoc-only") 3eaecd0c2333 ("usb: dwc3: gadget: Handle XferComplete for streams") 502a37b98a7b ("usb: dwc3: gadget: cache frame number in struct dwc3_ep") 66f5dd5a0379 ("usb: dwc3: gadget: rename done_trbs and done_reqs") 7fdca766499b ("usb: dwc3: gadget: simplify __dwc3_gadget_kick_transfer() prototype") 8f608e8ab628 ("usb: dwc3: gadget: remove unnecessary 'dwc' parameter") a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists") d80fe1b6e34d ("usb: dwc3: gadget: simplify short packet event") e0c42ce590fe ("usb: dwc3: gadget: simplify IOC handling") f38e35dd84e2 ("usb: dwc3: gadget: split dwc3_gadget_ep_cleanup_completed_requests()") fbea935accf4 ("usb: dwc3: gadget: rename dwc3_endpoint_transfer_complete()")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Currently dwc3 doesn't handle usb_request->zero for SG requests. This change checks and prepares extra TRBs for the ZLP for SG requests.
Cc: stable@vger.kernel.org Fixes: 04c03d10e507 ("usb: dwc3: gadget: handle request->zero") Signed-off-by: Thinh Nguyen thinhn@synopsys.com --- Changes in v2: - None
drivers/usb/dwc3/gadget.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index df603a817a98..c2a0f64f8d1e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1143,6 +1143,37 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, req->request.short_not_ok, req->request.no_interrupt, req->request.is_last); + } else if (req->request.zero && req->request.length && + !usb_endpoint_xfer_isoc(dep->endpoint.desc) && + !rem && !chain) { + struct dwc3 *dwc = dep->dwc; + struct dwc3_trb *trb; + + req->needs_extra_trb = true; + + /* Prepare normal TRB */ + dwc3_prepare_one_trb(dep, req, trb_length, true, i); + + /* 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, + !req->direction, 1, + req->request.stream_id, + req->request.short_not_ok, + req->request.no_interrupt, + req->request.is_last); + + /* Prepare one more TRB to handle MPS alignment */ + if (!req->direction) { + trb = &dep->trb_pool[dep->trb_enqueue]; + req->num_trbs++; + __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, + false, 1, req->request.stream_id, + req->request.short_not_ok, + req->request.no_interrupt, + req->request.is_last); + } } else { dwc3_prepare_one_trb(dep, req, trb_length, chain, i); }
linux-stable-mirror@lists.linaro.org