summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-05-01 20:36:19 -0400
committerNiket Sirsi <nsirsi@nvidia.com>2011-07-12 15:04:23 -0700
commita8fbdf9ff9dde552bf2049342b284a0667b2aedc (patch)
tree2cb4342d2b2b0434b68d97e6e5689f3bb0205750
parent77bb3984fc74852eec5d1aedac0edcdc686a388d (diff)
USB: gadget: f_mtp: Add support for queueing multiple interrupt requests
Fixes problem sending "store added" events when there are multiple stores Signed-off-by: Mike Lockwood <lockwood@android.com> (cherry picked from commit f937994b15d9d0433c027b9314afe0eabdbe0103) Change-Id: I9233074bc0ef1abb149df1e41e3c97eeebf66be4 Reviewed-on: http://git-master/r/36698 Reviewed-by: Amit Kamath <akamath@nvidia.com> Tested-by: Amit Kamath <akamath@nvidia.com> Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
-rw-r--r--drivers/usb/gadget/f_mtp.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c
index 92dd89b340bc..4de4c68bb8cb 100644
--- a/drivers/usb/gadget/f_mtp.c
+++ b/drivers/usb/gadget/f_mtp.c
@@ -53,6 +53,7 @@
/* number of tx and rx requests to allocate */
#define TX_REQ_MAX 4
#define RX_REQ_MAX 2
+#define INTR_REQ_MAX 5
/* ID for Microsoft MTP OS String */
#define MTP_OS_STRING_ID 0xEE
@@ -89,14 +90,13 @@ struct mtp_dev {
atomic_t ioctl_excl;
struct list_head tx_idle;
+ struct list_head intr_idle;
wait_queue_head_t read_wq;
wait_queue_head_t write_wq;
+ wait_queue_head_t intr_wq;
struct usb_request *rx_req[RX_REQ_MAX];
- struct usb_request *intr_req;
int rx_done;
- /* true if interrupt endpoint is busy */
- int intr_busy;
/* for processing MTP_SEND_FILE and MTP_RECEIVE_FILE
* ioctls on a work queue
@@ -372,11 +372,12 @@ static void mtp_complete_intr(struct usb_ep *ep, struct usb_request *req)
{
struct mtp_dev *dev = _mtp_dev;
- DBG(dev->cdev, "mtp_complete_intr status: %d actual: %d\n",
- req->status, req->actual);
- dev->intr_busy = 0;
if (req->status != 0)
dev->state = STATE_ERROR;
+
+ req_put(dev, &dev->intr_idle, req);
+
+ wake_up(&dev->intr_wq);
}
static int __init create_bulk_endpoints(struct mtp_dev *dev,
@@ -442,11 +443,13 @@ static int __init create_bulk_endpoints(struct mtp_dev *dev,
req->complete = mtp_complete_out;
dev->rx_req[i] = req;
}
- req = mtp_request_new(dev->ep_intr, INTR_BUFFER_SIZE);
- if (!req)
- goto fail;
- req->complete = mtp_complete_intr;
- dev->intr_req = req;
+ for (i = 0; i < INTR_REQ_MAX; i++) {
+ req = mtp_request_new(dev->ep_intr, INTR_BUFFER_SIZE);
+ if (!req)
+ goto fail;
+ req->complete = mtp_complete_intr;
+ req_put(dev, &dev->intr_idle, req);
+ }
return 0;
@@ -789,7 +792,7 @@ static void receive_file_work(struct work_struct *data)
static int mtp_send_event(struct mtp_dev *dev, struct mtp_event *event)
{
- struct usb_request *req;
+ struct usb_request *req= NULL;
int ret;
int length = event->length;
@@ -799,21 +802,20 @@ static int mtp_send_event(struct mtp_dev *dev, struct mtp_event *event)
return -EINVAL;
if (dev->state == STATE_OFFLINE)
return -ENODEV;
- /* unfortunately an interrupt request might hang indefinitely if the host
- * is not listening on the interrupt endpoint, so instead of waiting,
- * we just fail if the endpoint is busy.
- */
- if (dev->intr_busy)
- return -EBUSY;
- req = dev->intr_req;
- if (copy_from_user(req->buf, (void __user *)event->data, length))
+ ret = wait_event_interruptible_timeout(dev->intr_wq,
+ (req = req_get(dev, &dev->intr_idle)), msecs_to_jiffies(1000));
+ if (!req)
+ return -ETIME;
+
+ if (copy_from_user(req->buf, (void __user *)event->data, length)) {
+ req_put(dev, &dev->intr_idle, req);
return -EFAULT;
+ }
req->length = length;
- dev->intr_busy = 1;
ret = usb_ep_queue(dev->ep_intr, req, GFP_KERNEL);
if (ret)
- dev->intr_busy = 0;
+ req_put(dev, &dev->intr_idle, req);
return ret;
}
@@ -1014,7 +1016,8 @@ mtp_function_unbind(struct usb_configuration *c, struct usb_function *f)
mtp_request_free(req, dev->ep_in);
for (i = 0; i < RX_REQ_MAX; i++)
mtp_request_free(dev->rx_req[i], dev->ep_out);
- mtp_request_free(dev->intr_req, dev->ep_intr);
+ while ((req = req_get(dev, &dev->intr_idle)))
+ mtp_request_free(req, dev->ep_intr);
dev->state = STATE_OFFLINE;
spin_unlock_irq(&dev->lock);
@@ -1207,9 +1210,11 @@ static int mtp_bind_config(struct usb_configuration *c)
spin_lock_init(&dev->lock);
init_waitqueue_head(&dev->read_wq);
init_waitqueue_head(&dev->write_wq);
+ init_waitqueue_head(&dev->intr_wq);
atomic_set(&dev->open_excl, 0);
atomic_set(&dev->ioctl_excl, 0);
INIT_LIST_HEAD(&dev->tx_idle);
+ INIT_LIST_HEAD(&dev->intr_idle);
dev->wq = create_singlethread_workqueue("f_mtp");
if (!dev->wq)