linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: gadget: respect driver's max_speed
@ 2021-11-05 17:23 John Keeping
  2021-11-08  7:56 ` Minas Harutyunyan
  0 siblings, 1 reply; 3+ messages in thread
From: John Keeping @ 2021-11-05 17:23 UTC (permalink / raw)
  To: Minas Harutyunyan
  Cc: John Keeping, Greg Kroah-Hartman, linux-usb, linux-kernel

UDCs should not enumerate faster than the max_speed set by the gadget
driver.  Use this to further restrict the speed set in the DWC2
parameters so that the device will not connect faster than is supported
by the gadget driver.

For configfs-based composite devices this can be set via the max_speed
configfs file.

Signed-off-by: John Keeping <john@metanate.com>
---
 drivers/usb/dwc2/gadget.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 744539b78f6c..1f39c2f1be8e 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3377,6 +3377,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 	u32 val;
 	u32 usbcfg;
 	u32 dcfg = 0;
+	u8 speed;
 	int ep;
 
 	/* Kill any ep0 requests as controller will be reinitialized */
@@ -3418,7 +3419,22 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 
 	dcfg |= DCFG_EPMISCNT(1);
 
-	switch (hsotg->params.speed) {
+	speed = hsotg->params.speed;
+	if (hsotg->driver) {
+		switch (hsotg->driver->max_speed) {
+		case USB_SPEED_LOW:
+			speed = DWC2_SPEED_PARAM_LOW;
+			break;
+		case USB_SPEED_FULL:
+			if (speed != USB_SPEED_LOW)
+				speed = DWC2_SPEED_PARAM_FULL;
+			break;
+		default:
+			break;
+		}
+	}
+
+	switch (speed) {
 	case DWC2_SPEED_PARAM_LOW:
 		dcfg |= DCFG_DEVSPD_LS;
 		break;
-- 
2.33.1


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

* Re: [PATCH] usb: dwc2: gadget: respect driver's max_speed
  2021-11-05 17:23 [PATCH] usb: dwc2: gadget: respect driver's max_speed John Keeping
@ 2021-11-08  7:56 ` Minas Harutyunyan
  2021-11-08 14:44   ` John Keeping
  0 siblings, 1 reply; 3+ messages in thread
From: Minas Harutyunyan @ 2021-11-08  7:56 UTC (permalink / raw)
  To: John Keeping; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On 11/5/2021 9:23 PM, John Keeping wrote:
> UDCs should not enumerate faster than the max_speed set by the gadget
> driver.  Use this to further restrict the speed set in the DWC2
> parameters so that the device will not connect faster than is supported
> by the gadget driver.
> 
> For configfs-based composite devices this can be set via the max_speed
> configfs file.
> 
> Signed-off-by: John Keeping <john@metanate.com>

Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>


> ---
>   drivers/usb/dwc2/gadget.c | 18 +++++++++++++++++-
>   1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 744539b78f6c..1f39c2f1be8e 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -3377,6 +3377,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
>   	u32 val;
>   	u32 usbcfg;
>   	u32 dcfg = 0;
> +	u8 speed;
>   	int ep;
>   
>   	/* Kill any ep0 requests as controller will be reinitialized */
> @@ -3418,7 +3419,22 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
>   
>   	dcfg |= DCFG_EPMISCNT(1);
>   
> -	switch (hsotg->params.speed) {
> +	speed = hsotg->params.speed;
> +	if (hsotg->driver) {
> +		switch (hsotg->driver->max_speed) {
> +		case USB_SPEED_LOW:
> +			speed = DWC2_SPEED_PARAM_LOW;
> +			break;
> +		case USB_SPEED_FULL:
> +			if (speed != USB_SPEED_LOW)
> +				speed = DWC2_SPEED_PARAM_FULL;
> +			break;
> +		default:
> +			break;
> +		}
> +	}
> +
> +	switch (speed) {
>   	case DWC2_SPEED_PARAM_LOW:
>   		dcfg |= DCFG_DEVSPD_LS;
>   		break;
> 


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

* Re: [PATCH] usb: dwc2: gadget: respect driver's max_speed
  2021-11-08  7:56 ` Minas Harutyunyan
@ 2021-11-08 14:44   ` John Keeping
  0 siblings, 0 replies; 3+ messages in thread
From: John Keeping @ 2021-11-08 14:44 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 08, 2021 at 07:56:50AM +0000, Minas Harutyunyan wrote:
> On 11/5/2021 9:23 PM, John Keeping wrote:
> > UDCs should not enumerate faster than the max_speed set by the gadget
> > driver.  Use this to further restrict the speed set in the DWC2
> > parameters so that the device will not connect faster than is supported
> > by the gadget driver.
> > 
> > For configfs-based composite devices this can be set via the max_speed
> > configfs file.
> > 
> > Signed-off-by: John Keeping <john@metanate.com>
> 
> Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>

Actually, this isn't needed following commit 5324bad66f09 ("usb: dwc2:
gadget: implement udc_set_speed()") - I should have tested on something
more recent than 5.10.

There are still some problems in this area for dwc2 platforms that do
not support high-speed, but this patch is not the fix for them.  Please
drop this.


Sorry for the noise,
John


> > ---
> >   drivers/usb/dwc2/gadget.c | 18 +++++++++++++++++-
> >   1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> > index 744539b78f6c..1f39c2f1be8e 100644
> > --- a/drivers/usb/dwc2/gadget.c
> > +++ b/drivers/usb/dwc2/gadget.c
> > @@ -3377,6 +3377,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
> >   	u32 val;
> >   	u32 usbcfg;
> >   	u32 dcfg = 0;
> > +	u8 speed;
> >   	int ep;
> >   
> >   	/* Kill any ep0 requests as controller will be reinitialized */
> > @@ -3418,7 +3419,22 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
> >   
> >   	dcfg |= DCFG_EPMISCNT(1);
> >   
> > -	switch (hsotg->params.speed) {
> > +	speed = hsotg->params.speed;
> > +	if (hsotg->driver) {
> > +		switch (hsotg->driver->max_speed) {
> > +		case USB_SPEED_LOW:
> > +			speed = DWC2_SPEED_PARAM_LOW;
> > +			break;
> > +		case USB_SPEED_FULL:
> > +			if (speed != USB_SPEED_LOW)
> > +				speed = DWC2_SPEED_PARAM_FULL;
> > +			break;
> > +		default:
> > +			break;
> > +		}
> > +	}
> > +
> > +	switch (speed) {
> >   	case DWC2_SPEED_PARAM_LOW:
> >   		dcfg |= DCFG_DEVSPD_LS;
> >   		break;
> > 
> 

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

end of thread, other threads:[~2021-11-08 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 17:23 [PATCH] usb: dwc2: gadget: respect driver's max_speed John Keeping
2021-11-08  7:56 ` Minas Harutyunyan
2021-11-08 14:44   ` John Keeping

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).