linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: gadget: Fix .udc_set_speed()
@ 2017-10-31 13:01 Roger Quadros
  2017-10-31 13:24 ` Felipe Balbi
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Roger Quadros @ 2017-10-31 13:01 UTC (permalink / raw)
  To: balbi; +Cc: Dylan.Howey, linux-usb, linux-kernel, Roger Quadros, # v4 . 13+

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);
+
 	spin_lock_irqsave(&dwc->lock, flags);
 	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
 	reg &= ~(DWC3_DCFG_SPEED_MASK);
-- 
cheers,
-roger

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

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

* Re: [PATCH] usb: dwc3: gadget: Fix .udc_set_speed()
  2017-10-31 13:01 [PATCH] usb: dwc3: gadget: Fix .udc_set_speed() Roger Quadros
@ 2017-10-31 13:24 ` Felipe Balbi
  2017-10-31 13:27   ` Roger Quadros
  2017-10-31 13:47 ` [PATCH v2] " Roger Quadros
  2017-10-31 13:56 ` [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling Roger Quadros
  2 siblings, 1 reply; 11+ messages in thread
From: Felipe Balbi @ 2017-10-31 13:24 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Dylan.Howey, linux-usb, linux-kernel, Roger Quadros, # v4 . 13+

[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] usb: dwc3: gadget: Fix .udc_set_speed()
  2017-10-31 13:24 ` Felipe Balbi
@ 2017-10-31 13:27   ` Roger Quadros
  0 siblings, 0 replies; 11+ messages in thread
From: Roger Quadros @ 2017-10-31 13:27 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+


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

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

* [PATCH v2] usb: dwc3: gadget: Fix .udc_set_speed()
  2017-10-31 13:01 [PATCH] usb: dwc3: gadget: Fix .udc_set_speed() Roger Quadros
  2017-10-31 13:24 ` Felipe Balbi
@ 2017-10-31 13:47 ` Roger Quadros
  2017-10-31 13:54   ` Roger Quadros
  2017-10-31 13:56 ` [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling Roger Quadros
  2 siblings, 1 reply; 11+ messages in thread
From: Roger Quadros @ 2017-10-31 13:47 UTC (permalink / raw)
  To: balbi; +Cc: Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+, rogerq

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

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

* Re: [PATCH v2] usb: dwc3: gadget: Fix .udc_set_speed()
  2017-10-31 13:47 ` [PATCH v2] " Roger Quadros
@ 2017-10-31 13:54   ` Roger Quadros
  0 siblings, 0 replies; 11+ messages in thread
From: Roger Quadros @ 2017-10-31 13:54 UTC (permalink / raw)
  To: balbi; +Cc: Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

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

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

* [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-10-31 13:01 [PATCH] usb: dwc3: gadget: Fix .udc_set_speed() Roger Quadros
  2017-10-31 13:24 ` Felipe Balbi
  2017-10-31 13:47 ` [PATCH v2] " Roger Quadros
@ 2017-10-31 13:56 ` Roger Quadros
  2017-11-01 14:24   ` Alan Stern
  2 siblings, 1 reply; 11+ messages in thread
From: Roger Quadros @ 2017-10-31 13:56 UTC (permalink / raw)
  To: balbi; +Cc: Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+, rogerq

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

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

* Re: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-10-31 13:56 ` [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling Roger Quadros
@ 2017-11-01 14:24   ` Alan Stern
  2017-11-01 15:11     ` Roger Quadros
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Stern @ 2017-11-01 14:24 UTC (permalink / raw)
  To: Roger Quadros; +Cc: balbi, Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

On Tue, 31 Oct 2017, 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);
> +	}
>  }
>  
>  /**

Roger, would you like to send in a follow-up patch that removes the now 
unnecessary code from dummy_udc_set_speed() in dummy_hcd.c?

Alan Stern

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

* Re: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-11-01 14:24   ` Alan Stern
@ 2017-11-01 15:11     ` Roger Quadros
  2017-11-01 15:45       ` Alan Stern
  0 siblings, 1 reply; 11+ messages in thread
From: Roger Quadros @ 2017-11-01 15:11 UTC (permalink / raw)
  To: Alan Stern; +Cc: balbi, Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

Hi Alan,

On 01/11/17 16:24, Alan Stern wrote:
> On Tue, 31 Oct 2017, 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);
>> +	}
>>  }
>>  
>>  /**
> 
> Roger, would you like to send in a follow-up patch that removes the now 
> unnecessary code from dummy_udc_set_speed() in dummy_hcd.c?
> 

Sure. I have a question though.

In dummy_udc_set_speed() we should just set gadget.speed to whatever is passed in speed.
This will be the maximum supported speed by the gadget function driver.

However, is it possible that the gadget will be connected at a lower speed than that?

I see gadget.speed being updated in dummy_hub_control() GetPortStatus: case, but not
in case of USB_SPEED_HIGH and USB_SPEED_LOW.

-- 
cheers,
-roger

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

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

* Re: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-11-01 15:11     ` Roger Quadros
@ 2017-11-01 15:45       ` Alan Stern
  2017-11-02  8:53         ` Roger Quadros
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Stern @ 2017-11-01 15:45 UTC (permalink / raw)
  To: Roger Quadros; +Cc: balbi, Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

On Wed, 1 Nov 2017, Roger Quadros wrote:

> > Roger, would you like to send in a follow-up patch that removes the now 
> > unnecessary code from dummy_udc_set_speed() in dummy_hcd.c?
> > 
> 
> Sure. I have a question though.
> 
> In dummy_udc_set_speed() we should just set gadget.speed to whatever is passed in speed.
> This will be the maximum supported speed by the gadget function driver.

Following your patch, it will be the maximum speed supported by the 
gadget function driver or the maximum speed supported by the UDC 
driver, whichever is lower.  That's the whole point of your patch, 
right?

> However, is it possible that the gadget will be connected at a lower speed than that?

Yes, it is possible to connect at a speed lower than the function 
driver's maximum speed.  The connection speed for dummy-hcd is 
controlled by a pair of module parameters: is_super_speed and 
is_high_speed.

> I see gadget.speed being updated in dummy_hub_control() GetPortStatus: case, but not
> in case of USB_SPEED_HIGH and USB_SPEED_LOW.

Here's what the code does, in outline form:

	switch (dum_hcd->dum->gadget.speed) {
	case USB_SPEED_HIGH:
		...
		break;
	case USB_SPEED_LOW:
		...
		break;
	default:
		dum_hcd->dum->gadget.speed = USB_SPEED_FULL;
		break;
	}

In other words, if gadget.speed isn't USB_SPEED_HIGH or USB_SPEED_LOW, 
set it to USB_SPEED_FULL.  And this is all under the case where the 
connection is USB-2, not USB-3 or higher.

How is this related to the requested change to dummy_udc_set_speed()?

Alan Stern

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

* Re: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-11-01 15:45       ` Alan Stern
@ 2017-11-02  8:53         ` Roger Quadros
  2017-11-02 14:14           ` Alan Stern
  0 siblings, 1 reply; 11+ messages in thread
From: Roger Quadros @ 2017-11-02  8:53 UTC (permalink / raw)
  To: Alan Stern; +Cc: balbi, Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

On 01/11/17 17:45, Alan Stern wrote:
> On Wed, 1 Nov 2017, Roger Quadros wrote:
> 
>>> Roger, would you like to send in a follow-up patch that removes the now 
>>> unnecessary code from dummy_udc_set_speed() in dummy_hcd.c?
>>>
>>
>> Sure. I have a question though.
>>
>> In dummy_udc_set_speed() we should just set gadget.speed to whatever is passed in speed.
>> This will be the maximum supported speed by the gadget function driver.
> 
> Following your patch, it will be the maximum speed supported by the 
> gadget function driver or the maximum speed supported by the UDC 
> driver, whichever is lower.  That's the whole point of your patch, 
> right?

Yes.

> 
>> However, is it possible that the gadget will be connected at a lower speed than that?
> 
> Yes, it is possible to connect at a speed lower than the function 
> driver's maximum speed.  The connection speed for dummy-hcd is 
> controlled by a pair of module parameters: is_super_speed and 
> is_high_speed.
> 
>> I see gadget.speed being updated in dummy_hub_control() GetPortStatus: case, but not
>> in case of USB_SPEED_HIGH and USB_SPEED_LOW.
> 
> Here's what the code does, in outline form:
> 
> 	switch (dum_hcd->dum->gadget.speed) {
> 	case USB_SPEED_HIGH:
> 		...
> 		break;
> 	case USB_SPEED_LOW:
> 		...
> 		break;
> 	default:
> 		dum_hcd->dum->gadget.speed = USB_SPEED_FULL;
> 		break;
> 	}
> 
> In other words, if gadget.speed isn't USB_SPEED_HIGH or USB_SPEED_LOW, 
> set it to USB_SPEED_FULL.  And this is all under the case where the 
> connection is USB-2, not USB-3 or higher.
> 
> How is this related to the requested change to dummy_udc_set_speed()?

With or without the requested change to dummy_udc_set_speed() there will
never be a case when gadget.speed isn't already USB_SPEED_FULL
if connection is USB-2 and gadget.speed is not USB_SPEED_HIGH or USB_SPEED_LOW.

So in the above code snippet, default: portion is redundant.

But that can be fixed in a separate patch.

-- 
cheers,
-roger

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

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

* Re: [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling
  2017-11-02  8:53         ` Roger Quadros
@ 2017-11-02 14:14           ` Alan Stern
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Stern @ 2017-11-02 14:14 UTC (permalink / raw)
  To: Roger Quadros; +Cc: balbi, Dylan.Howey, linux-usb, linux-kernel, # v4 . 13+

On Thu, 2 Nov 2017, Roger Quadros wrote:

> On 01/11/17 17:45, Alan Stern wrote:
> > On Wed, 1 Nov 2017, Roger Quadros wrote:
> > 
> >>> Roger, would you like to send in a follow-up patch that removes the now 
> >>> unnecessary code from dummy_udc_set_speed() in dummy_hcd.c?
> >>>
> >>
> >> Sure. I have a question though.
> >>
> >> In dummy_udc_set_speed() we should just set gadget.speed to whatever is passed in speed.
> >> This will be the maximum supported speed by the gadget function driver.
> > 
> > Following your patch, it will be the maximum speed supported by the 
> > gadget function driver or the maximum speed supported by the UDC 
> > driver, whichever is lower.  That's the whole point of your patch, 
> > right?
> 
> Yes.
> 
> > 
> >> However, is it possible that the gadget will be connected at a lower speed than that?
> > 
> > Yes, it is possible to connect at a speed lower than the function 
> > driver's maximum speed.  The connection speed for dummy-hcd is 
> > controlled by a pair of module parameters: is_super_speed and 
> > is_high_speed.
> > 
> >> I see gadget.speed being updated in dummy_hub_control() GetPortStatus: case, but not
> >> in case of USB_SPEED_HIGH and USB_SPEED_LOW.
> > 
> > Here's what the code does, in outline form:
> > 
> > 	switch (dum_hcd->dum->gadget.speed) {
> > 	case USB_SPEED_HIGH:
> > 		...
> > 		break;
> > 	case USB_SPEED_LOW:
> > 		...
> > 		break;
> > 	default:
> > 		dum_hcd->dum->gadget.speed = USB_SPEED_FULL;
> > 		break;
> > 	}
> > 
> > In other words, if gadget.speed isn't USB_SPEED_HIGH or USB_SPEED_LOW, 
> > set it to USB_SPEED_FULL.  And this is all under the case where the 
> > connection is USB-2, not USB-3 or higher.
> > 
> > How is this related to the requested change to dummy_udc_set_speed()?
> 
> With or without the requested change to dummy_udc_set_speed() there will
> never be a case when gadget.speed isn't already USB_SPEED_FULL
> if connection is USB-2 and gadget.speed is not USB_SPEED_HIGH or USB_SPEED_LOW.
> 
> So in the above code snippet, default: portion is redundant.
> 
> But that can be fixed in a separate patch.

Ah, I see.  Yes, you can change this too if you want.

Alan Stern

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

end of thread, other threads:[~2017-11-02 14:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31 13:01 [PATCH] usb: dwc3: gadget: Fix .udc_set_speed() Roger Quadros
2017-10-31 13:24 ` Felipe Balbi
2017-10-31 13:27   ` Roger Quadros
2017-10-31 13:47 ` [PATCH v2] " Roger Quadros
2017-10-31 13:54   ` Roger Quadros
2017-10-31 13:56 ` [PATCH v2][RESEND] usb: gadget: core: Fix ->udc_set_speed() speed handling Roger Quadros
2017-11-01 14:24   ` Alan Stern
2017-11-01 15:11     ` Roger Quadros
2017-11-01 15:45       ` Alan Stern
2017-11-02  8:53         ` Roger Quadros
2017-11-02 14:14           ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).