Skip to contentSkip to conversation

usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

PATCH New Patrice Chotard 2 participants 8 messages Feb 10, 2021 – Feb 17, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Fixes c791c8431c34 ("usb: dwc2: convert driver to DM_USB_GADGET")

---

 drivers/usb/gadget/dwc2_udc_otg.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/usb/gadget/dwc2_udc_otg.c +2 -8
index e3871e381e..4f3d761eb1 100644
@@ -248,10 +248,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 
 	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
-	if (!driver
-	    || (driver->speed != USB_SPEED_FULL
-		&& driver->speed != USB_SPEED_HIGH)
-	    || !driver->bind || !driver->disconnect || !driver->setup)
+	if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
 		return -EINVAL;
 	if (!dev)
 		return -ENODEV;
@@ -320,10 +317,7 @@ static int dwc2_gadget_start(struct usb_gadget *g,
 
 	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
-	if (!driver ||
-	    (driver->speed != USB_SPEED_FULL &&
-	     driver->speed != USB_SPEED_HIGH) ||
-	    !driver->bind || !driver->disconnect || !driver->setup)
+	if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
 		return -EINVAL;
 
 	if (!dev)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

What is really going on when this fails ?

Quoted 37 lines
Fixes c791c8431c34 ("usb: dwc2: convert driver to DM_USB_GADGET")

---

  drivers/usb/gadget/dwc2_udc_otg.c | 10 ++--------
  1 file changed, 2 insertions(+), 8 deletions(-)
drivers/usb/gadget/dwc2_udc_otg.c +2 -8
index e3871e381e..4f3d761eb1 100644
@@ -248,10 +248,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 
  	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
-	if (!driver
-	    || (driver->speed != USB_SPEED_FULL
-		&& driver->speed != USB_SPEED_HIGH)
-	    || !driver->bind || !driver->disconnect || !driver->setup)
+	if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
  		return -EINVAL;
  	if (!dev)
  		return -ENODEV;
@@ -320,10 +317,7 @@ static int dwc2_gadget_start(struct usb_gadget *g,
 
  	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
-	if (!driver ||
-	    (driver->speed != USB_SPEED_FULL &&
-	     driver->speed != USB_SPEED_HIGH) ||
-	    !driver->bind || !driver->disconnect || !driver->setup)
+	if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
  		return -EINVAL;
 
  	if (!dev)

[...]

#2 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

I am not sure this speed test is needed.

Quoted 2 lines

What is really going on when this fails ?

Since 8745b9ebccae ("usb: gadget: add super speed support"), driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

and this forbids dwc2_udc_otg.c to be registered.

Patrice

Quoted 36 lines
Quoted 33 lines
Fixes c791c8431c34 ("usb: dwc2: convert driver to DM_USB_GADGET")

---

? drivers/usb/gadget/dwc2_udc_otg.c | 10 ++-------- ? 1 file changed, 2 insertions(+), 8 deletions(-)

drivers/usb/gadget/dwc2_udc_otg.c +0 -0
index e3871e381e..4f3d761eb1 100644
@@ -248,10 +248,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 ? ????? debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

? -??? if (!driver
-??????? || (driver->speed != USB_SPEED_FULL
-??????? && driver->speed != USB_SPEED_HIGH)
-??????? || !driver->bind || !driver->disconnect || !driver->setup) +??? if (!driver || !driver->bind || !driver->disconnect || !driver->setup) ????????? return -EINVAL;
????? if (!dev)
????????? return -ENODEV;

drivers/usb/gadget/dwc2_udc_otg.c +0 -0
@@ -320,10 +317,7 @@ static int dwc2_gadget_start(struct usb_gadget *g,
 ? ????? debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

? -??? if (!driver ||
-??????? (driver->speed != USB_SPEED_FULL &&
-???????? driver->speed != USB_SPEED_HIGH) ||
-??????? !driver->bind || !driver->disconnect || !driver->setup) +??? if (!driver || !driver->bind || !driver->disconnect || !driver->setup) ????????? return -EINVAL;
? ????? if (!dev)

[...]

#3 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Quoted 15 lines · Patrice CHOTARD

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

I am not sure this speed test is needed.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

What is really going on when this fails ?

Since 8745b9ebccae ("usb: gadget: add super speed support"), driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

and this forbids dwc2_udc_otg.c to be registered.

That sounds like a bug in the USB gadget/otg core , no ?

#4 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Hi Marek

Quoted 19 lines · Marek Vasut
Quoted 18 lines · Patrice CHOTARD

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

I am not sure this speed test is needed.

Quoted 2 lines

What is really going on when this fails ?

Quoted 6 lines
Quoted 4 lines

Since 8745b9ebccae ("usb: gadget: add super speed support"), driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

and this forbids dwc2_udc_otg.c to be registered.

That sounds like a bug in the USB gadget/otg core , no ?

After analysis, if i correctly understood, the speed test done in both usb_gadget_register_driver() and in dwc2_gadget_start() in dwc2_udc_otg.c is too restrictive and accepts only gadget driver with max speed equal to USB_SPEED_FULL or USB_SPEED_HIGH.

So all gadget driver with max speed set to higher speed than USB_SPEED_HIGH (USB_SPEED_SUPER in case of composite gadget driver) are not allowed, which is wrong.

This test should check that the gadget driver max speed is higher or equal to the min speed supported by dwc2_udc_otg driver, ie USB_SPEED_FULL.

So the test should be :

@@ -247,12 +247,11 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
unsigned long flags = 0;

debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

if (!driver
- || (driver->speed != USB_SPEED_FULL
- && driver->speed != USB_SPEED_HIGH)

+	    || driver->speed < USB_SPEED_FULL
 	    || !driver->bind || !driver->disconnect || !driver->setup)

return -EINVAL;
if (!dev)
return -ENODEV;
if (dev->driver)
@@ -319,12 +318,11 @@ static int dwc2_gadget_start(struct usb_gadget *g,
struct dwc2_udc *dev = the_controller;

debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

if (!driver ||
- (driver->speed != USB_SPEED_FULL &&
- driver->speed != USB_SPEED_HIGH) ||
+ driver->speed < USB_SPEED_FULL ||
!driver->bind || !driver->disconnect || !driver->setup)
return -EINVAL;

if (!dev)

I you are agree, i will send a v2 with this.

Patrice

#5 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Quoted 1 line · Patrice CHOTARD

Hi Marek

Hi,

Quoted 23 lines · Marek Vasut
Quoted 22 lines · Patrice CHOTARD
Quoted 21 lines

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

I am not sure this speed test is needed.

Quoted 2 lines

What is really going on when this fails ?

Since 8745b9ebccae ("usb: gadget: add super speed support"), driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

and this forbids dwc2_udc_otg.c to be registered.

That sounds like a bug in the USB gadget/otg core , no ?

After analysis, if i correctly understood, the speed test done in both usb_gadget_register_driver() and in dwc2_gadget_start() in dwc2_udc_otg.c is too restrictive and accepts only gadget driver with max speed equal to USB_SPEED_FULL or USB_SPEED_HIGH.

That should be fine for the DWC2 IP, which is LS/FS/HS.

Quoted 23 lines

So all gadget driver with max speed set to higher speed than USB_SPEED_HIGH (USB_SPEED_SUPER in case of composite gadget driver) are not allowed, which is wrong.

This test should check that the gadget driver max speed is higher or equal to the min speed supported by dwc2_udc_otg driver, ie USB_SPEED_FULL.

So the test should be :

drivers/usb/gadget/dwc2_udc_otg.c +1 -2
@@ -247,12 +247,11 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
  	unsigned long flags = 0;
 
  	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
  	if (!driver
-	    || (driver->speed != USB_SPEED_FULL
-		&& driver->speed != USB_SPEED_HIGH)
+	    || driver->speed < USB_SPEED_FULL
  	    || !driver->bind || !driver->disconnect || !driver->setup)
  		return -EINVAL;
  	if (!dev)
  		return -ENODEV;
  	if (dev->driver)

drivers/usb/gadget/dwc2_udc_otg.c static int dwc2_gadget_start(struct usb_gadget *g, · line 323

Quoted 8 lines
drivers/usb/gadget/dwc2_udc_otg.c +1 -2
@@ -319,12 +318,11 @@ static int dwc2_gadget_start(struct usb_gadget *g,
  	struct dwc2_udc *dev = the_controller;
 
  	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
  	if (!driver ||
-	    (driver->speed != USB_SPEED_FULL &&
-	     driver->speed != USB_SPEED_HIGH) ||
+	    driver->speed < USB_SPEED_FULL ||

The DWC2 can't operate in LS gadget mode , i.e. emulate some old keyboard ? Maybe what you want is driver->speed > USB_SPEED_HIGH instead ?

Quoted 6 lines
drivers/usb/gadget/dwc2_udc_otg.c +0 -0
  	    !driver->bind || !driver->disconnect || !driver->setup)
  		return -EINVAL;
 
  	if (!dev)
 

I you are agree, i will send a v2 with this.

Yes please. But you really want to get AB/RB from Lukasz, since he does the gadget stuff.

#6 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Hi Marek

Quoted 59 lines · Marek Vasut
Quoted 1 line · Patrice CHOTARD

Hi Marek

Hi,

Quoted 23 lines · Marek Vasut
Quoted 22 lines · Patrice CHOTARD
Quoted 21 lines

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 5 lines · Patrice Chotard

Since commit 8745b9ebccae ("usb: gadget: add super speed support") ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it. Tested on stm32mp157c-ev1 board.

Isn't the speed check correct though ?

I am not sure this speed test is needed.

Quoted 2 lines

What is really going on when this fails ?

Since 8745b9ebccae ("usb: gadget: add super speed support"), driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

and this forbids dwc2_udc_otg.c to be registered.

That sounds like a bug in the USB gadget/otg core , no ?

After analysis, if i correctly understood, the speed test done in both usb_gadget_register_driver() and in dwc2_gadget_start() in dwc2_udc_otg.c is too restrictive and accepts only gadget driver with max speed equal to USB_SPEED_FULL or USB_SPEED_HIGH.

That should be fine for the DWC2 IP, which is LS/FS/HS.

Quoted 21 lines

So all gadget driver with max speed set to higher speed than USB_SPEED_HIGH (USB_SPEED_SUPER in case of composite gadget driver) are not allowed, which is wrong.

This test should check that the gadget driver max speed is higher or equal to the min speed supported by dwc2_udc_otg driver, ie USB_SPEED_FULL.

So the test should be :

(quoted diff) +0 -0
@@ -247,12 +247,11 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 ????? unsigned long flags = 0;
 ? ????? debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

? ????? if (!driver
-??????? || (driver->speed != USB_SPEED_FULL
-??????? && driver->speed != USB_SPEED_HIGH)
+??????? || driver->speed < USB_SPEED_FULL
????????? || !driver->bind || !driver->disconnect || !driver->setup) ????????? return -EINVAL;
????? if (!dev)
????????? return -ENODEV;
????? if (dev->driver)

(quoted diff) +0 -0
@@ -319,12 +318,11 @@ static int dwc2_gadget_start(struct usb_gadget *g,
Quoted 8 lines
Quoted 6 lines
(quoted diff) +0 -0
 ????? struct dwc2_udc *dev = the_controller;
 ? ????? debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");

? ????? if (!driver ||
-??????? (driver->speed != USB_SPEED_FULL &&
-???????? driver->speed != USB_SPEED_HIGH) ||
+??????? driver->speed < USB_SPEED_FULL ||

The DWC2 can't operate in LS gadget mode , i.e. emulate some old keyboard ? Maybe what you want is driver->speed > USB_SPEED_HIGH instead ?

The test is correct, in case driver->speed is lower than FS, we return -EINVAL. All others speed FS/HS/SS and higher are allowed.

Quoted 8 lines
Quoted 6 lines

????????? !driver->bind || !driver->disconnect || !driver->setup) ????????? return -EINVAL;
? ????? if (!dev)

I you are agree, i will send a v2 with this.

Yes please. But you really want to get AB/RB from Lukasz, since he does the gadget stuff.

Ok, i will add Lukasz for the V2 review.

Thanks
Patrice

#7 lore raw

PATCH 1/1 usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

Quoted 1 line · Patrice CHOTARD

Hi Marek

Hi,

[...]

Quoted 11 lines
Quoted 9 lines

Review static int dwc2_gadget_start(struct usb_gadget *g, · line 321

Quoted 7 lines
(quoted diff) +1 -2
@@ -319,12 +318,11 @@ static int dwc2_gadget_start(struct usb_gadget *g,
 ????? struct dwc2_udc *dev = the_controller;
 ? ????? debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 ? ????? if (!driver ||
-??????? (driver->speed != USB_SPEED_FULL &&
-???????? driver->speed != USB_SPEED_HIGH) ||
+??????? driver->speed < USB_SPEED_FULL ||

The DWC2 can't operate in LS gadget mode , i.e. emulate some old keyboard ? Maybe what you want is driver->speed > USB_SPEED_HIGH instead ?

The test is correct, in case driver->speed is lower than FS, we return -EINVAL. All others speed FS/HS/SS and higher are allowed.

What's the problem with LS ?

[...]