usb: dwc3: gadget: Fix .udc_set_speed()

Message ID 1509454904-4966-1-git-send-email-rogerq@ti.com
State New
Headers show
Series
  • usb: dwc3: gadget: Fix .udc_set_speed()
Related show

Commit Message

Roger Quadros Oct. 31, 2017, 1:01 p.m.
UDC core calls .udc_set_speed() with the speed parameter
containing the maximum speed supported by the gadget function
driver. This might very well be more or less than that
supported by the dwc3 controller driver.

Select the lesser of the 2 speeds so both are operating
within limits.

This fixes PHY Erratic errors and 2 second enumeration delay on
TI's AM437x platforms.

Fixes: 7d8d0639565f ("usb: dwc3: gadget: implement ->udc_set_speed()")
Cc: <stable@vger.kernel.org> # v4.13+
Reported-by: Dylan Howey <Dylan.Howey@tennantco.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>

---
 drivers/usb/dwc3/gadget.c | 2 ++
 1 file changed, 2 insertions(+)

-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Comments

Felipe Balbi Oct. 31, 2017, 1:24 p.m. | #1
Roger Quadros <rogerq@ti.com> writes:

> UDC core calls .udc_set_speed() with the speed parameter

> containing the maximum speed supported by the gadget function

> driver. This might very well be more or less than that

> supported by the dwc3 controller driver.

>

> Select the lesser of the 2 speeds so both are operating

> within limits.

>

> This fixes PHY Erratic errors and 2 second enumeration delay on

> TI's AM437x platforms.

>

> Fixes: 7d8d0639565f ("usb: dwc3: gadget: implement ->udc_set_speed()")

> Cc: <stable@vger.kernel.org> # v4.13+

> Reported-by: Dylan Howey <Dylan.Howey@tennantco.com>

> Signed-off-by: Roger Quadros <rogerq@ti.com>

> ---

>  drivers/usb/dwc3/gadget.c | 2 ++

>  1 file changed, 2 insertions(+)

>

> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c

> index f064f15..9f27ec0 100644

> --- a/drivers/usb/dwc3/gadget.c

> +++ b/drivers/usb/dwc3/gadget.c

> @@ -2008,6 +2008,8 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,

>  	unsigned long		flags;

>  	u32			reg;

>  

> +	speed = min(g->max_speed, speed);


should we do that in udc core itself?

@@ -1080,8 +1080,12 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
 					    enum usb_device_speed speed)
 {
-	if (udc->gadget->ops->udc_set_speed)
-		udc->gadget->ops->udc_set_speed(udc->gadget, speed);
+	if (udc->gadget->ops->udc_set_speed) {
+		enum usb_device_speed s;
+
+		s = min(speed, udc->gadget->max_speed);
+		udc->gadget->ops->udc_set_speed(udc->gadget, s);
+	}
 }
 
 /**

then the fix applies for all UDCs.

-- 
balbi
Roger Quadros Oct. 31, 2017, 1:27 p.m. | #2

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

On 31/10/17 15:24, Felipe Balbi wrote:
> Roger Quadros <rogerq@ti.com> writes:

> 

>> UDC core calls .udc_set_speed() with the speed parameter

>> containing the maximum speed supported by the gadget function

>> driver. This might very well be more or less than that

>> supported by the dwc3 controller driver.

>>

>> Select the lesser of the 2 speeds so both are operating

>> within limits.

>>

>> This fixes PHY Erratic errors and 2 second enumeration delay on

>> TI's AM437x platforms.

>>

>> Fixes: 7d8d0639565f ("usb: dwc3: gadget: implement ->udc_set_speed()")

>> Cc: <stable@vger.kernel.org> # v4.13+

>> Reported-by: Dylan Howey <Dylan.Howey@tennantco.com>

>> Signed-off-by: Roger Quadros <rogerq@ti.com>

>> ---

>>  drivers/usb/dwc3/gadget.c | 2 ++

>>  1 file changed, 2 insertions(+)

>>

>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c

>> index f064f15..9f27ec0 100644

>> --- a/drivers/usb/dwc3/gadget.c

>> +++ b/drivers/usb/dwc3/gadget.c

>> @@ -2008,6 +2008,8 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g,

>>  	unsigned long		flags;

>>  	u32			reg;

>>  

>> +	speed = min(g->max_speed, speed);

> 

> should we do that in udc core itself?

> 

> @@ -1080,8 +1080,12 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc)

>  static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,

>  					    enum usb_device_speed speed)

>  {

> -	if (udc->gadget->ops->udc_set_speed)

> -		udc->gadget->ops->udc_set_speed(udc->gadget, speed);

> +	if (udc->gadget->ops->udc_set_speed) {

> +		enum usb_device_speed s;

> +

> +		s = min(speed, udc->gadget->max_speed);

> +		udc->gadget->ops->udc_set_speed(udc->gadget, s);

> +	}

>  }

>  

>  /**

> 

> then the fix applies for all UDCs.

> 


Sounds like a good idea. Will re-spin this patch.

-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Roger Quadros Oct. 31, 2017, 1:54 p.m. | #3
Felipe,

Forgot to update subject :P.
Will resend.

On 31/10/17 15:47, Roger Quadros wrote:
> Currently UDC core calls ->udc_set_speed() with the speed parameter

> containing the maximum speed supported by the gadget function

> driver. This might very well be more than that supported by the

> UDC controller driver.

> 

> Select the lesser of the 2 speeds so both UDC and gadget function

> driver are operating within limits.

> 

> This fixes PHY Erratic errors and 2 second enumeration delay on

> TI's AM437x platforms.

> 

> Fixes: 6099eca796ae ("usb: gadget: core: introduce ->udc_set_speed() method")

> Cc: <stable@vger.kernel.org> # v4.13+

> Reported-by: Dylan Howey <Dylan.Howey@tennantco.com>

> Signed-off-by: Roger Quadros <rogerq@ti.com>

> ---

> v2:

> - Move speed limiting code to UDC core.

> 

>  drivers/usb/gadget/udc/core.c | 8 ++++++--

>  1 file changed, 6 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c

> index d41d07a..def1b05 100644

> --- a/drivers/usb/gadget/udc/core.c

> +++ b/drivers/usb/gadget/udc/core.c

> @@ -1080,8 +1080,12 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc)

>  static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,

>  					    enum usb_device_speed speed)

>  {

> -	if (udc->gadget->ops->udc_set_speed)

> -		udc->gadget->ops->udc_set_speed(udc->gadget, speed);

> +	if (udc->gadget->ops->udc_set_speed) {

> +		enum usb_device_speed s;

> +

> +		s = min(speed, udc->gadget->max_speed);

> +		udc->gadget->ops->udc_set_speed(udc->gadget, s);

> +	}

>  }

>  

>  /**

> 


-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Patch

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f064f15..9f27ec0 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2008,6 +2008,8 @@  static void dwc3_gadget_set_speed(struct usb_gadget *g,
 	unsigned long		flags;
 	u32			reg;
 
+	speed = min(g->max_speed, speed);
+
 	spin_lock_irqsave(&dwc->lock, flags);
 	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
 	reg &= ~(DWC3_DCFG_SPEED_MASK);