Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 6144062

Browse files
Thinh Nguyengregkh
authored andcommitted
usb: dwc3: gadget: Cleanup SG handling
The current logic in dwc3 driver is tracking req->num_queued_sgs and req->sg. But they can be checked base on the num_pending_sgs and num_trbs. They are redundant and can complicate the SG logic. Let's remove them. Signed-off-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/96c7bf8f6b3e91e607d5b78ea51cb1d00c614eaf.1731545781.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b7fc65f commit 6144062

File tree

2 files changed

+7
-38
lines changed

2 files changed

+7
-38
lines changed

drivers/usb/dwc3/core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,8 @@ struct dwc3_hwparams {
941941
* @request: struct usb_request to be transferred
942942
* @list: a list_head used for request queueing
943943
* @dep: struct dwc3_ep owning this request
944-
* @sg: pointer to first incomplete sg
945944
* @start_sg: pointer to the sg which should be queued next
946945
* @num_pending_sgs: counter to pending sgs
947-
* @num_queued_sgs: counter to the number of sgs which already got queued
948946
* @remaining: amount of data remaining
949947
* @status: internal dwc3 request status tracking
950948
* @epnum: endpoint number to which this request refers
@@ -964,7 +962,6 @@ struct dwc3_request {
964962
struct scatterlist *start_sg;
965963

966964
unsigned int num_pending_sgs;
967-
unsigned int num_queued_sgs;
968965
unsigned int remaining;
969966

970967
unsigned int status;

drivers/usb/dwc3/gadget.c

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,6 @@ static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
15441544
if (!last_sg)
15451545
req->start_sg = sg_next(s);
15461546

1547-
req->num_queued_sgs++;
15481547
req->num_pending_sgs--;
15491548

15501549
/*
@@ -1625,9 +1624,7 @@ static int dwc3_prepare_trbs(struct dwc3_ep *dep)
16251624
if (ret)
16261625
return ret;
16271626

1628-
req->sg = req->request.sg;
1629-
req->start_sg = req->sg;
1630-
req->num_queued_sgs = 0;
1627+
req->start_sg = req->request.sg;
16311628
req->num_pending_sgs = req->request.num_mapped_sgs;
16321629

16331630
if (req->num_pending_sgs > 0) {
@@ -3472,40 +3469,26 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep,
34723469
int status)
34733470
{
34743471
struct dwc3_trb *trb;
3475-
struct scatterlist *sg = req->sg;
3476-
struct scatterlist *s;
3477-
unsigned int num_queued = req->num_queued_sgs;
3472+
unsigned int num_completed_trbs = req->num_trbs;
34783473
unsigned int i;
34793474
int ret = 0;
34803475

3481-
for_each_sg(sg, s, num_queued, i) {
3476+
for (i = 0; i < num_completed_trbs; i++) {
34823477
trb = &dep->trb_pool[dep->trb_dequeue];
34833478

3484-
req->sg = sg_next(s);
3485-
req->num_queued_sgs--;
3486-
34873479
ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
3488-
trb, event, status, true);
3480+
trb, event, status,
3481+
!!(trb->ctrl & DWC3_TRB_CTRL_CHN));
34893482
if (ret)
34903483
break;
34913484
}
34923485

34933486
return ret;
34943487
}
34953488

3496-
static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep,
3497-
struct dwc3_request *req, const struct dwc3_event_depevt *event,
3498-
int status)
3499-
{
3500-
struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue];
3501-
3502-
return dwc3_gadget_ep_reclaim_completed_trb(dep, req, trb,
3503-
event, status, false);
3504-
}
3505-
35063489
static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req)
35073490
{
3508-
return req->num_pending_sgs == 0 && req->num_queued_sgs == 0;
3491+
return req->num_pending_sgs == 0 && req->num_trbs == 0;
35093492
}
35103493

35113494
static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
@@ -3515,24 +3498,13 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
35153498
int request_status;
35163499
int ret;
35173500

3518-
if (req->request.num_mapped_sgs)
3519-
ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
3520-
status);
3521-
else
3522-
ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
3523-
status);
3501+
ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event, status);
35243502

35253503
req->request.actual = req->request.length - req->remaining;
35263504

35273505
if (!dwc3_gadget_ep_request_completed(req))
35283506
goto out;
35293507

3530-
if (req->needs_extra_trb) {
3531-
ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
3532-
status);
3533-
req->needs_extra_trb = false;
3534-
}
3535-
35363508
/*
35373509
* The event status only reflects the status of the TRB with IOC set.
35383510
* For the requests that don't set interrupt on completion, the driver

0 commit comments

Comments
 (0)