usb: xhci: Limit transfer length of a single TD
authorDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 7 Nov 2016 05:34:15 +0000 (14:34 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 12 Oct 2022 04:31:37 +0000 (13:31 +0900)
This is workaround solution for timed out error and babble error while
transfering data exceeding 0x3F01FF bytes on xhci host. Actually, this
size equals to value that the maximum number of TRBs per TD times the
maximum size of transfer buffer on TRB. Thus, huge transfer request is
splitted in order to limit the size of data in a single TD.

Even though the single I/O request is splitted into multiple requests,
the transfer speed has affected insignificantly: 22.6 --> 22.3 MiB/s.

Change-Id: I85a17910587b70807f075dd40634a0da817cea2f
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
drivers/usb/host/xhci.c

index dbeb88afe37025392f337ef1dc6ce2ee78971fc9..1a5363d17dabba0131555e43838db2f67f043623 100644 (file)
@@ -1129,12 +1129,40 @@ static int _xhci_submit_int_msg(struct usb_device *udev, unsigned long pipe,
 static int _xhci_submit_bulk_msg(struct usb_device *udev, unsigned long pipe,
                                 void *buffer, int length)
 {
+       int ret;
+       int xfer_max_per_td, xfer_length, buf_pos;
+
        if (usb_pipetype(pipe) != PIPE_BULK) {
                printf("non-bulk pipe (type=%lu)", usb_pipetype(pipe));
                return -EINVAL;
        }
 
-       return xhci_bulk_tx(udev, pipe, length, buffer);
+       /*
+        * When transfering data exceeding the maximum number of TRBs per
+        * TD (default 64) is requested, the transfer fails with babble
+        * error or time out.
+        *
+        * Thus, huge data transfer should be splitted into multiple TDs.
+        */
+       xfer_max_per_td = TRB_MAX_BUFF_SIZE * (TRBS_PER_SEGMENT - 1);
+
+       buf_pos = 0;
+       do {
+               if (length > xfer_max_per_td)
+                       xfer_length = xfer_max_per_td;
+               else
+                       xfer_length = length;
+
+               ret = xhci_bulk_tx(udev, pipe, xfer_length, buffer + buf_pos);
+               if (ret < 0)
+                       return ret;
+
+               buf_pos += xfer_length;
+               length -= xfer_length;
+
+       } while (length > 0);
+
+       return ret;
 }
 
 /**