OSDN Git Service

usb: gadget: f_accessory: Make RX buffer size aligned to EP's MTU
authorHemant Kumar <hemantk@codeaurora.org>
Mon, 2 May 2016 20:26:15 +0000 (13:26 -0700)
committerHemant Kumar <hemantk@codeaurora.org>
Wed, 10 Aug 2016 21:24:31 +0000 (14:24 -0700)
Synopsys USB3 Controller (DWC3) has a restriction where size
of OUT requests (TRB) queued to the controller must be aligned
with the endpoint's max packet size. Generally, accessory userspace
module submits RX requests not aligned to endpoint's max packet
size. Hence to overcome this, align the size of RX request buffer to
endpoint's max packet while submitting to DCD as the buffers are
already allocated with the size of 16KB.

Change-Id: I3acdfc055d0c6a79a0aa65a715bae06dc475d078
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
drivers/usb/gadget/function/f_accessory.c

index 908cfb3..381443c 100644 (file)
@@ -609,8 +609,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
 {
        struct acc_dev *dev = fp->private_data;
        struct usb_request *req;
-       ssize_t r = count;
-       unsigned xfer;
+       ssize_t r = count, xfer, len;
        int ret = 0;
 
        pr_debug("acc_read(%zu)\n", count);
@@ -623,6 +622,8 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
        if (count > BULK_BUFFER_SIZE)
                count = BULK_BUFFER_SIZE;
 
+       len = ALIGN(count, dev->ep_out->maxpacket);
+
        /* we will block until we're online */
        pr_debug("acc_read: waiting for online\n");
        ret = wait_event_interruptible(dev->read_wq, dev->online);
@@ -640,7 +641,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
 requeue_req:
        /* queue a request */
        req = dev->rx_req[0];
-       req->length = count;
+       req->length = len;
        dev->rx_done = 0;
        ret = usb_ep_queue(dev->ep_out, req, GFP_KERNEL);
        if (ret < 0) {