diff mbox series

[U-Boot,RFC] usb: composite: Fix max packet size for USB3.0

Message ID 1544615364-13206-1-git-send-email-siva.durga.paladugu@xilinx.com
State RFC
Delegated to: Marek Vasut
Headers show
Series [U-Boot,RFC] usb: composite: Fix max packet size for USB3.0 | expand

Commit Message

Siva Durga Prasad Paladugu Dec. 12, 2018, 11:49 a.m. UTC
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. With out 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>
---
 drivers/usb/gadget/composite.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

Marek Vasut Dec. 12, 2018, 12:18 p.m. UTC | #1
On 12/12/2018 12:49 PM, 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. With out 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>

CCing Bin, I'd like his AB/RB.

> ---
>  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;
>
Bin Meng Dec. 12, 2018, 12:58 p.m. UTC | #2
On Wed, Dec 12, 2018 at 8:54 PM Marek Vasut <marex@denx.de> wrote:
>
> On 12/12/2018 12:49 PM, Siva Durga Prasad Paladugu wrote:
> > For USB3.0 the max packetsize for GET_DESCRIPTOR should be

nits: USB 3.0, packet size

> > 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. With out this patch, the max packet size is

nits: Without

> > 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>
>
> CCing Bin, I'd like his AB/RB.
>
> > ---
> >  drivers/usb/gadget/composite.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> >

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Regards,
Bin
diff mbox series

Patch

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;