Skip to content

Commit e192cc7

Browse files
mgrzeschikgregkh
authored andcommitted
usb: dwc3: gadget: move cmd_endtransfer to extra function
This patch adds the extra function __dwc3_stop_active_transfer to consolidate the same codepath. Signed-off-by: Michael Grzeschik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 26d27a1 commit e192cc7

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,40 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)
16731673
return DWC3_DSTS_SOFFN(reg);
16741674
}
16751675

1676+
/**
1677+
* __dwc3_stop_active_transfer - stop the current active transfer
1678+
* @dep: isoc endpoint
1679+
* @force: set forcerm bit in the command
1680+
* @interrupt: command complete interrupt after End Transfer command
1681+
*
1682+
* When setting force, the ForceRM bit will be set. In that case
1683+
* the controller won't update the TRB progress on command
1684+
* completion. It also won't clear the HWO bit in the TRB.
1685+
* The command will also not complete immediately in that case.
1686+
*/
1687+
static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt)
1688+
{
1689+
struct dwc3_gadget_ep_cmd_params params;
1690+
u32 cmd;
1691+
int ret;
1692+
1693+
cmd = DWC3_DEPCMD_ENDTRANSFER;
1694+
cmd |= force ? DWC3_DEPCMD_HIPRI_FORCERM : 0;
1695+
cmd |= interrupt ? DWC3_DEPCMD_CMDIOC : 0;
1696+
cmd |= DWC3_DEPCMD_PARAM(dep->resource_index);
1697+
memset(&params, 0, sizeof(params));
1698+
ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
1699+
WARN_ON_ONCE(ret);
1700+
dep->resource_index = 0;
1701+
1702+
if (!interrupt)
1703+
dep->flags &= ~DWC3_EP_TRANSFER_STARTED;
1704+
else if (!ret)
1705+
dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
1706+
1707+
return ret;
1708+
}
1709+
16761710
/**
16771711
* dwc3_gadget_start_isoc_quirk - workaround invalid frame number
16781712
* @dep: isoc endpoint
@@ -1848,21 +1882,8 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
18481882
* status, issue END_TRANSFER command and retry on the next XferNotReady
18491883
* event.
18501884
*/
1851-
if (ret == -EAGAIN) {
1852-
struct dwc3_gadget_ep_cmd_params params;
1853-
u32 cmd;
1854-
1855-
cmd = DWC3_DEPCMD_ENDTRANSFER |
1856-
DWC3_DEPCMD_CMDIOC |
1857-
DWC3_DEPCMD_PARAM(dep->resource_index);
1858-
1859-
dep->resource_index = 0;
1860-
memset(&params, 0, sizeof(params));
1861-
1862-
ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
1863-
if (!ret)
1864-
dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
1865-
}
1885+
if (ret == -EAGAIN)
1886+
ret = __dwc3_stop_active_transfer(dep, false, true);
18661887

18671888
return ret;
18681889
}
@@ -3603,10 +3624,6 @@ static void dwc3_reset_gadget(struct dwc3 *dwc)
36033624
static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force,
36043625
bool interrupt)
36053626
{
3606-
struct dwc3_gadget_ep_cmd_params params;
3607-
u32 cmd;
3608-
int ret;
3609-
36103627
if (!(dep->flags & DWC3_EP_TRANSFER_STARTED) ||
36113628
(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
36123629
return;
@@ -3638,19 +3655,7 @@ static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force,
36383655
* This mode is NOT available on the DWC_usb31 IP.
36393656
*/
36403657

3641-
cmd = DWC3_DEPCMD_ENDTRANSFER;
3642-
cmd |= force ? DWC3_DEPCMD_HIPRI_FORCERM : 0;
3643-
cmd |= interrupt ? DWC3_DEPCMD_CMDIOC : 0;
3644-
cmd |= DWC3_DEPCMD_PARAM(dep->resource_index);
3645-
memset(&params, 0, sizeof(params));
3646-
ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
3647-
WARN_ON_ONCE(ret);
3648-
dep->resource_index = 0;
3649-
3650-
if (!interrupt)
3651-
dep->flags &= ~DWC3_EP_TRANSFER_STARTED;
3652-
else
3653-
dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
3658+
__dwc3_stop_active_transfer(dep, force, interrupt);
36543659
}
36553660

36563661
static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)

0 commit comments

Comments
 (0)