Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup
@ 2020-12-29 23:00 Wesley Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: Wesley Cheng @ 2020-12-29 23:00 UTC (permalink / raw)
  To: balbi, gregkh; +Cc: linux-kernel, linux-usb, Wesley Cheng

usb_gadget_deactivate/usb_gadget_activate does not execute the UDC start
operation, which may leave EP0 disabled and event IRQs disabled when
re-activating the function. Move the enabling/disabling of USB EP0 and
device event IRQs to be performed in the pullup routine.

Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the
controller")

Tested-by: Michael Tretter <m.tretter@pengutronix.de>
Reported-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
---
 drivers/usb/dwc3/gadget.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 5d879b7606d5..922c8b76e534 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1988,6 +1988,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 
 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
 static void __dwc3_gadget_stop(struct dwc3 *dwc);
+static int __dwc3_gadget_start(struct dwc3 *dwc);
 
 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 {
@@ -2050,6 +2051,8 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 			dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
 						dwc->ev_buf->length;
 		}
+	} else {
+		__dwc3_gadget_start(dwc);
 	}
 
 	ret = dwc3_gadget_run_stop(dwc, is_on, false);
@@ -2224,10 +2227,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 	}
 
 	dwc->gadget_driver	= driver;
-
-	if (pm_runtime_active(dwc->dev))
-		__dwc3_gadget_start(dwc);
-
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
 	return 0;
@@ -2253,13 +2252,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 	unsigned long		flags;
 
 	spin_lock_irqsave(&dwc->lock, flags);
-
-	if (pm_runtime_suspended(dwc->dev))
-		goto out;
-
-	__dwc3_gadget_stop(dwc);
-
-out:
 	dwc->gadget_driver	= NULL;
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup
  2020-11-20 15:08 ` Michael Tretter
@ 2020-11-30 11:46   ` Michael Tretter
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Tretter @ 2020-11-30 11:46 UTC (permalink / raw)
  To: Wesley Cheng; +Cc: balbi, gregkh, linux-kernel, linux-usb, Thinh.Nguyen, kernel

On Fri, 20 Nov 2020 16:08:04 +0100, Michael Tretter wrote:
> On Thu, 19 Nov 2020 16:13:21 -0800, Wesley Cheng wrote:
> > usb_gadget_deactivate/usb_gadget_activate does not execute the UDC start
> > operation, which may leave EP0 disabled and event IRQs disabled when
> > re-activating the function. Move the enabling/disabling of USB EP0 and
> > device event IRQs to be performed in the pullup routine.
> > 
> > Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the
> > controller")
> > 
> > Reported-by: Michael Tretter <m.tretter@pengutronix.de>
> > Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
> 
> Tested-by: Michael Tretter <m.tretter@pengutronix.de>

Gentle ping. I didn't see this fix being picked up into any of the usb trees.

Michael

> 
> > ---
> >  drivers/usb/dwc3/gadget.c | 14 +++-----------
> >  1 file changed, 3 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > index 5d879b7606d5..922c8b76e534 100644
> > --- a/drivers/usb/dwc3/gadget.c
> > +++ b/drivers/usb/dwc3/gadget.c
> > @@ -1988,6 +1988,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
> >  
> >  static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
> >  static void __dwc3_gadget_stop(struct dwc3 *dwc);
> > +static int __dwc3_gadget_start(struct dwc3 *dwc);
> >  
> >  static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
> >  {
> > @@ -2050,6 +2051,8 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
> >  			dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
> >  						dwc->ev_buf->length;
> >  		}
> > +	} else {
> > +		__dwc3_gadget_start(dwc);
> >  	}
> >  
> >  	ret = dwc3_gadget_run_stop(dwc, is_on, false);
> > @@ -2224,10 +2227,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
> >  	}
> >  
> >  	dwc->gadget_driver	= driver;
> > -
> > -	if (pm_runtime_active(dwc->dev))
> > -		__dwc3_gadget_start(dwc);
> > -
> >  	spin_unlock_irqrestore(&dwc->lock, flags);
> >  
> >  	return 0;
> > @@ -2253,13 +2252,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
> >  	unsigned long		flags;
> >  
> >  	spin_lock_irqsave(&dwc->lock, flags);
> > -
> > -	if (pm_runtime_suspended(dwc->dev))
> > -		goto out;
> > -
> > -	__dwc3_gadget_stop(dwc);
> > -
> > -out:
> >  	dwc->gadget_driver	= NULL;
> >  	spin_unlock_irqrestore(&dwc->lock, flags);
> >  
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > a Linux Foundation Collaborative Project
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup
  2020-11-20  0:13 Wesley Cheng
@ 2020-11-20 15:08 ` Michael Tretter
  2020-11-30 11:46   ` Michael Tretter
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Tretter @ 2020-11-20 15:08 UTC (permalink / raw)
  To: Wesley Cheng; +Cc: balbi, gregkh, linux-kernel, linux-usb, Thinh.Nguyen

On Thu, 19 Nov 2020 16:13:21 -0800, Wesley Cheng wrote:
> usb_gadget_deactivate/usb_gadget_activate does not execute the UDC start
> operation, which may leave EP0 disabled and event IRQs disabled when
> re-activating the function. Move the enabling/disabling of USB EP0 and
> device event IRQs to be performed in the pullup routine.
> 
> Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the
> controller")
> 
> Reported-by: Michael Tretter <m.tretter@pengutronix.de>
> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>

Tested-by: Michael Tretter <m.tretter@pengutronix.de>

> ---
>  drivers/usb/dwc3/gadget.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 5d879b7606d5..922c8b76e534 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1988,6 +1988,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
>  
>  static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
>  static void __dwc3_gadget_stop(struct dwc3 *dwc);
> +static int __dwc3_gadget_start(struct dwc3 *dwc);
>  
>  static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  {
> @@ -2050,6 +2051,8 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  			dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
>  						dwc->ev_buf->length;
>  		}
> +	} else {
> +		__dwc3_gadget_start(dwc);
>  	}
>  
>  	ret = dwc3_gadget_run_stop(dwc, is_on, false);
> @@ -2224,10 +2227,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
>  	}
>  
>  	dwc->gadget_driver	= driver;
> -
> -	if (pm_runtime_active(dwc->dev))
> -		__dwc3_gadget_start(dwc);
> -
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
>  	return 0;
> @@ -2253,13 +2252,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>  	unsigned long		flags;
>  
>  	spin_lock_irqsave(&dwc->lock, flags);
> -
> -	if (pm_runtime_suspended(dwc->dev))
> -		goto out;
> -
> -	__dwc3_gadget_stop(dwc);
> -
> -out:
>  	dwc->gadget_driver	= NULL;
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup
@ 2020-11-20  0:13 Wesley Cheng
  2020-11-20 15:08 ` Michael Tretter
  0 siblings, 1 reply; 4+ messages in thread
From: Wesley Cheng @ 2020-11-20  0:13 UTC (permalink / raw)
  To: balbi, gregkh
  Cc: linux-kernel, linux-usb, Thinh.Nguyen, m.tretter, Wesley Cheng

usb_gadget_deactivate/usb_gadget_activate does not execute the UDC start
operation, which may leave EP0 disabled and event IRQs disabled when
re-activating the function. Move the enabling/disabling of USB EP0 and
device event IRQs to be performed in the pullup routine.

Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the
controller")

Reported-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
---
 drivers/usb/dwc3/gadget.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 5d879b7606d5..922c8b76e534 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1988,6 +1988,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 
 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
 static void __dwc3_gadget_stop(struct dwc3 *dwc);
+static int __dwc3_gadget_start(struct dwc3 *dwc);
 
 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 {
@@ -2050,6 +2051,8 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 			dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
 						dwc->ev_buf->length;
 		}
+	} else {
+		__dwc3_gadget_start(dwc);
 	}
 
 	ret = dwc3_gadget_run_stop(dwc, is_on, false);
@@ -2224,10 +2227,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 	}
 
 	dwc->gadget_driver	= driver;
-
-	if (pm_runtime_active(dwc->dev))
-		__dwc3_gadget_start(dwc);
-
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
 	return 0;
@@ -2253,13 +2252,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 	unsigned long		flags;
 
 	spin_lock_irqsave(&dwc->lock, flags);
-
-	if (pm_runtime_suspended(dwc->dev))
-		goto out;
-
-	__dwc3_gadget_stop(dwc);
-
-out:
 	dwc->gadget_driver	= NULL;
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29 23:00 [PATCH] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup Wesley Cheng
  -- strict thread matches above, loose matches on Subject: below --
2020-11-20  0:13 Wesley Cheng
2020-11-20 15:08 ` Michael Tretter
2020-11-30 11:46   ` Michael Tretter

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git