public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] usb: composite: Fix max packet size for USB3.0
@ 2018-12-13  9:46 Siva Durga Prasad Paladugu
  2018-12-13 13:24 ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Siva Durga Prasad Paladugu @ 2018-12-13  9:46 UTC (permalink / raw)
  To: u-boot

For USB3.0, the max packetsize for GET_DESCRIPTOR should be
sent as exponent value for 2. This means for 512, max packet
size should be filled with 9(2^9=512). Also, fill the USB
version field with 3.0 if speed is negotiated to Superspeed.
This fixes the issue of DFU gadget download failure with
superspeed. Without this patch, the max packet size is
overflowed to zero as the bMaxPacketsize is of u8 and hence
host is not able to detect this device.

Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---
Changes from RFC:
- Fixed typo in description as per comment.
---
 drivers/usb/gadget/composite.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5106cc5..c7e7623 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -735,8 +735,21 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 		case USB_DT_DEVICE:
 			cdev->desc.bNumConfigurations =
 				count_configs(cdev, USB_DT_DEVICE);
-			cdev->desc.bMaxPacketSize0 =
-				cdev->gadget->ep0->maxpacket;
+
+			/*
+			 * If the speed is Super speed, then the supported
+			 * max packet size is 512 and it should be sent as
+			 * exponent of 2. So, 9(2^9=512) should be filled in
+			 * bMaxPacketSize0. Also fill USB version as 3.0
+			 * if speed is Super speed.
+			 */
+			if (cdev->gadget->speed == USB_SPEED_SUPER) {
+				cdev->desc.bMaxPacketSize0 = 9;
+				cdev->desc.bcdUSB = cpu_to_le16(0x0300);
+			} else {
+				cdev->desc.bMaxPacketSize0 =
+					cdev->gadget->ep0->maxpacket;
+			}
 			value = min(w_length, (u16) sizeof cdev->desc);
 			memcpy(req->buf, &cdev->desc, value);
 			break;
-- 
2.7.4

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

* [U-Boot] [PATCH] usb: composite: Fix max packet size for USB3.0
  2018-12-13  9:46 [U-Boot] [PATCH] usb: composite: Fix max packet size for USB3.0 Siva Durga Prasad Paladugu
@ 2018-12-13 13:24 ` Marek Vasut
  2018-12-13 13:38   ` Lukasz Majewski
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2018-12-13 13:24 UTC (permalink / raw)
  To: u-boot

On 12/13/2018 10:46 AM, Siva Durga Prasad Paladugu wrote:
> For USB3.0, the max packetsize for GET_DESCRIPTOR should be
> sent as exponent value for 2. This means for 512, max packet
> size should be filled with 9(2^9=512). Also, fill the USB
> version field with 3.0 if speed is negotiated to Superspeed.
> This fixes the issue of DFU gadget download failure with
> superspeed. Without this patch, the max packet size is
> overflowed to zero as the bMaxPacketsize is of u8 and hence
> host is not able to detect this device.
> 
> Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> ---
> Changes from RFC:
> - Fixed typo in description as per comment.
> ---
>  drivers/usb/gadget/composite.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 5106cc5..c7e7623 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -735,8 +735,21 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
>  		case USB_DT_DEVICE:
>  			cdev->desc.bNumConfigurations =
>  				count_configs(cdev, USB_DT_DEVICE);
> -			cdev->desc.bMaxPacketSize0 =
> -				cdev->gadget->ep0->maxpacket;
> +
> +			/*
> +			 * If the speed is Super speed, then the supported
> +			 * max packet size is 512 and it should be sent as
> +			 * exponent of 2. So, 9(2^9=512) should be filled in
> +			 * bMaxPacketSize0. Also fill USB version as 3.0
> +			 * if speed is Super speed.
> +			 */
> +			if (cdev->gadget->speed == USB_SPEED_SUPER) {
> +				cdev->desc.bMaxPacketSize0 = 9;
> +				cdev->desc.bcdUSB = cpu_to_le16(0x0300);
> +			} else {
> +				cdev->desc.bMaxPacketSize0 =
> +					cdev->gadget->ep0->maxpacket;
> +			}
>  			value = min(w_length, (u16) sizeof cdev->desc);
>  			memcpy(req->buf, &cdev->desc, value);
>  			break;
> 
Applied, thanks

-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH] usb: composite: Fix max packet size for USB3.0
  2018-12-13 13:24 ` Marek Vasut
@ 2018-12-13 13:38   ` Lukasz Majewski
  0 siblings, 0 replies; 3+ messages in thread
From: Lukasz Majewski @ 2018-12-13 13:38 UTC (permalink / raw)
  To: u-boot

On Thu, 13 Dec 2018 14:24:32 +0100
Marek Vasut <marex@denx.de> wrote:

> On 12/13/2018 10:46 AM, Siva Durga Prasad Paladugu wrote:
> > For USB3.0, the max packetsize for GET_DESCRIPTOR should be
> > sent as exponent value for 2. This means for 512, max packet
> > size should be filled with 9(2^9=512). Also, fill the USB
> > version field with 3.0 if speed is negotiated to Superspeed.
> > This fixes the issue of DFU gadget download failure with
> > superspeed. Without this patch, the max packet size is
> > overflowed to zero as the bMaxPacketsize is of u8 and hence
> > host is not able to detect this device.
> > 
> > Signed-off-by: Siva Durga Prasad Paladugu
> > <siva.durga.paladugu@xilinx.com> Reviewed-by: Bin Meng
> > <bmeng.cn@gmail.com> ---
> > Changes from RFC:
> > - Fixed typo in description as per comment.
> > ---
> >  drivers/usb/gadget/composite.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/gadget/composite.c
> > b/drivers/usb/gadget/composite.c index 5106cc5..c7e7623 100644
> > --- a/drivers/usb/gadget/composite.c
> > +++ b/drivers/usb/gadget/composite.c
> > @@ -735,8 +735,21 @@ composite_setup(struct usb_gadget *gadget,
> > const struct usb_ctrlrequest *ctrl) case USB_DT_DEVICE:
> >  			cdev->desc.bNumConfigurations =
> >  				count_configs(cdev, USB_DT_DEVICE);
> > -			cdev->desc.bMaxPacketSize0 =
> > -				cdev->gadget->ep0->maxpacket;
> > +
> > +			/*
> > +			 * If the speed is Super speed, then the
> > supported
> > +			 * max packet size is 512 and it should be
> > sent as
> > +			 * exponent of 2. So, 9(2^9=512) should be
> > filled in
> > +			 * bMaxPacketSize0. Also fill USB version
> > as 3.0
> > +			 * if speed is Super speed.
> > +			 */
> > +			if (cdev->gadget->speed ==
> > USB_SPEED_SUPER) {
> > +				cdev->desc.bMaxPacketSize0 = 9;
> > +				cdev->desc.bcdUSB =
> > cpu_to_le16(0x0300);
> > +			} else {
> > +				cdev->desc.bMaxPacketSize0 =
> > +
> > cdev->gadget->ep0->maxpacket;
> > +			}
> >  			value = min(w_length, (u16) sizeof
> > cdev->desc); memcpy(req->buf, &cdev->desc, value);
> >  			break;
> >   
> Applied, thanks
> 

Just for completeness:

Acked-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181213/fc3ce156/attachment.sig>

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

end of thread, other threads:[~2018-12-13 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-13  9:46 [U-Boot] [PATCH] usb: composite: Fix max packet size for USB3.0 Siva Durga Prasad Paladugu
2018-12-13 13:24 ` Marek Vasut
2018-12-13 13:38   ` Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox