Skip to content

Commit 4fe4f9f

Browse files
Minas HarutyunyanFelipe Balbi
Minas Harutyunyan
authored and
Felipe Balbi
committed
usb: dwc2: Fix disable all EP's on disconnect
Disabling all EP's allow to reset EP's to initial state. Introduced new function dwc2_hsotg_ep_disable_lock() which before calling dwc2_hsotg_ep_disable() function acquire hsotg->lock and release on exiting. From dwc2_hsotg_ep_disable() function removed acquiring hsotg->lock. In dwc2_hsotg_core_init_disconnected() function when USB reset interrupt asserted disabling all ep’s by dwc2_hsotg_ep_disable() function. This updates eliminating sparse imbalance warnings. Reverted changes in dwc2_hostg_disconnect() function. Introduced new function dwc2_hsotg_ep_disable_lock(). Changed dwc2_hsotg_ep_ops. Now disable point to dwc2_hsotg_ep_disable_lock() function. In functions dwc2_hsotg_udc_stop() and dwc2_hsotg_suspend() dwc2_hsotg_ep_disable() function replaced by dwc2_hsotg_ep_disable_lock() function. In dwc2_hsotg_ep_disable() function removed acquiring of hsotg->lock. Fixes: dccf1ba ("usb: dwc2: Disable all EP's on disconnect") Signed-off-by: Minas Harutyunyan <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 244add8 commit 4fe4f9f

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

drivers/usb/dwc2/gadget.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,8 +3165,6 @@ static void kill_all_requests(struct dwc2_hsotg *hsotg,
31653165
dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index);
31663166
}
31673167

3168-
static int dwc2_hsotg_ep_disable(struct usb_ep *ep);
3169-
31703168
/**
31713169
* dwc2_hsotg_disconnect - disconnect service
31723170
* @hsotg: The device state.
@@ -3188,9 +3186,11 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg)
31883186
/* all endpoints should be shutdown */
31893187
for (ep = 0; ep < hsotg->num_of_eps; ep++) {
31903188
if (hsotg->eps_in[ep])
3191-
dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep);
3189+
kill_all_requests(hsotg, hsotg->eps_in[ep],
3190+
-ESHUTDOWN);
31923191
if (hsotg->eps_out[ep])
3193-
dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep);
3192+
kill_all_requests(hsotg, hsotg->eps_out[ep],
3193+
-ESHUTDOWN);
31943194
}
31953195

31963196
call_gadget(hsotg, disconnect);
@@ -3234,6 +3234,7 @@ static void dwc2_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic)
32343234
GINTSTS_PTXFEMP | \
32353235
GINTSTS_RXFLVL)
32363236

3237+
static int dwc2_hsotg_ep_disable(struct usb_ep *ep);
32373238
/**
32383239
* dwc2_hsotg_core_init - issue softreset to the core
32393240
* @hsotg: The device state
@@ -4069,10 +4070,8 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
40694070
struct dwc2_hsotg *hsotg = hs_ep->parent;
40704071
int dir_in = hs_ep->dir_in;
40714072
int index = hs_ep->index;
4072-
unsigned long flags;
40734073
u32 epctrl_reg;
40744074
u32 ctrl;
4075-
int locked;
40764075

40774076
dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep);
40784077

@@ -4088,10 +4087,6 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
40884087

40894088
epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
40904089

4091-
locked = spin_is_locked(&hsotg->lock);
4092-
if (!locked)
4093-
spin_lock_irqsave(&hsotg->lock, flags);
4094-
40954090
ctrl = dwc2_readl(hsotg, epctrl_reg);
40964091

40974092
if (ctrl & DXEPCTL_EPENA)
@@ -4114,12 +4109,22 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
41144109
hs_ep->fifo_index = 0;
41154110
hs_ep->fifo_size = 0;
41164111

4117-
if (!locked)
4118-
spin_unlock_irqrestore(&hsotg->lock, flags);
4119-
41204112
return 0;
41214113
}
41224114

4115+
static int dwc2_hsotg_ep_disable_lock(struct usb_ep *ep)
4116+
{
4117+
struct dwc2_hsotg_ep *hs_ep = our_ep(ep);
4118+
struct dwc2_hsotg *hsotg = hs_ep->parent;
4119+
unsigned long flags;
4120+
int ret;
4121+
4122+
spin_lock_irqsave(&hsotg->lock, flags);
4123+
ret = dwc2_hsotg_ep_disable(ep);
4124+
spin_unlock_irqrestore(&hsotg->lock, flags);
4125+
return ret;
4126+
}
4127+
41234128
/**
41244129
* on_list - check request is on the given endpoint
41254130
* @ep: The endpoint to check.
@@ -4267,7 +4272,7 @@ static int dwc2_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value)
42674272

42684273
static const struct usb_ep_ops dwc2_hsotg_ep_ops = {
42694274
.enable = dwc2_hsotg_ep_enable,
4270-
.disable = dwc2_hsotg_ep_disable,
4275+
.disable = dwc2_hsotg_ep_disable_lock,
42714276
.alloc_request = dwc2_hsotg_ep_alloc_request,
42724277
.free_request = dwc2_hsotg_ep_free_request,
42734278
.queue = dwc2_hsotg_ep_queue_lock,
@@ -4407,9 +4412,9 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget)
44074412
/* all endpoints should be shutdown */
44084413
for (ep = 1; ep < hsotg->num_of_eps; ep++) {
44094414
if (hsotg->eps_in[ep])
4410-
dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep);
4415+
dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep);
44114416
if (hsotg->eps_out[ep])
4412-
dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep);
4417+
dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep);
44134418
}
44144419

44154420
spin_lock_irqsave(&hsotg->lock, flags);
@@ -4857,9 +4862,9 @@ int dwc2_hsotg_suspend(struct dwc2_hsotg *hsotg)
48574862

48584863
for (ep = 0; ep < hsotg->num_of_eps; ep++) {
48594864
if (hsotg->eps_in[ep])
4860-
dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep);
4865+
dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep);
48614866
if (hsotg->eps_out[ep])
4862-
dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep);
4867+
dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep);
48634868
}
48644869
}
48654870

0 commit comments

Comments
 (0)