usb: composite: Fix max packet size for USB3.0
authorSiva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Thu, 13 Dec 2018 09:46:36 +0000 (15:16 +0530)
committerMarek Vasut <marex@denx.de>
Fri, 14 Dec 2018 16:59:10 +0000 (17:59 +0100)
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>
drivers/usb/gadget/composite.c

index 5106cc56cb6f59b76835fee903fd0cc32109e14a..c7e76237475260df0cccc5f688d816b1df99cc31 100644 (file)
@@ -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;