Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 487f020c authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: gadget: f_mtp: Increase default TX buffer size"

parents d8065f88 00d171a3
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@

#include "configfs.h"

#define MTP_RX_BUFFER_INIT_SIZE    1048576
#define MTP_TX_BUFFER_INIT_SIZE    1048576
#define MTP_BULK_BUFFER_SIZE       16384
#define INTR_BUFFER_SIZE           28
#define MAX_INST_NAME_LEN          40
@@ -78,10 +80,10 @@

#define MAX_ITERATION		100

unsigned int mtp_rx_req_len = MTP_BULK_BUFFER_SIZE;
unsigned int mtp_rx_req_len = MTP_RX_BUFFER_INIT_SIZE;
module_param(mtp_rx_req_len, uint, 0644);

unsigned int mtp_tx_req_len = MTP_BULK_BUFFER_SIZE;
unsigned int mtp_tx_req_len = MTP_TX_BUFFER_INIT_SIZE;
module_param(mtp_tx_req_len, uint, 0644);

unsigned int mtp_tx_reqs = MTP_TX_REQ_MAX;
@@ -455,7 +457,7 @@ static void mtp_complete_in(struct usb_ep *ep, struct usb_request *req)
{
	struct mtp_dev *dev = _mtp_dev;

	if (req->status != 0)
	if (req->status != 0 && dev->state != STATE_OFFLINE)
		dev->state = STATE_ERROR;

	mtp_req_put(dev, &dev->tx_idle, req);
@@ -468,7 +470,7 @@ static void mtp_complete_out(struct usb_ep *ep, struct usb_request *req)
	struct mtp_dev *dev = _mtp_dev;

	dev->rx_done = 1;
	if (req->status != 0)
	if (req->status != 0 && dev->state != STATE_OFFLINE)
		dev->state = STATE_ERROR;

	wake_up(&dev->read_wq);
@@ -478,7 +480,7 @@ static void mtp_complete_intr(struct usb_ep *ep, struct usb_request *req)
{
	struct mtp_dev *dev = _mtp_dev;

	if (req->status != 0)
	if (req->status != 0 && dev->state != STATE_OFFLINE)
		dev->state = STATE_ERROR;

	mtp_req_put(dev, &dev->intr_idle, req);
@@ -526,9 +528,6 @@ static int mtp_create_bulk_endpoints(struct mtp_dev *dev,
	dev->ep_intr = ep;

retry_tx_alloc:
	if (mtp_tx_req_len > MTP_BULK_BUFFER_SIZE)
		mtp_tx_reqs = 4;

	/* now allocate requests for our endpoints */
	for (i = 0; i < mtp_tx_reqs; i++) {
		req = mtp_request_new(dev->ep_in, mtp_tx_req_len);
@@ -592,7 +591,7 @@ static ssize_t mtp_read(struct file *fp, char __user *buf,
	ssize_t r = count, xfer, len;
	int ret = 0;

	DBG(cdev, "mtp_read(%zu)\n", count);
	DBG(cdev, "%s(%zu) state:%d\n", __func__, count, dev->state);

	/* we will block until we're online */
	DBG(cdev, "mtp_read: waiting for online state\n");
@@ -686,7 +685,7 @@ static ssize_t mtp_read(struct file *fp, char __user *buf,
		dev->state = STATE_READY;
	spin_unlock_irq(&dev->lock);

	DBG(cdev, "mtp_read returning %zd\n", r);
	DBG(cdev, "%s returning %zd state:%d\n", __func__, r, dev->state);
	return r;
}

@@ -701,7 +700,7 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf,
	int sendZLP = 0;
	int ret;

	DBG(cdev, "mtp_write(%zu)\n", count);
	DBG(cdev, "%s(%zu) state:%d\n", __func__, count, dev->state);

	spin_lock_irq(&dev->lock);
	if (dev->state == STATE_CANCELED) {
@@ -740,12 +739,14 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf,
			((req = mtp_req_get(dev, &dev->tx_idle))
				|| dev->state != STATE_BUSY));
		if (!req) {
			DBG(cdev, "%s request NULL ret:%d state:%d\n",
				__func__, ret, dev->state);
			r = ret;
			break;
		}

		if (count > MTP_BULK_BUFFER_SIZE)
			xfer = MTP_BULK_BUFFER_SIZE;
		if (count > mtp_tx_req_len)
			xfer = mtp_tx_req_len;
		else
			xfer = count;
		if (xfer && copy_from_user(req->buf, buf, xfer)) {
@@ -778,7 +779,7 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf,
		dev->state = STATE_READY;
	spin_unlock_irq(&dev->lock);

	DBG(cdev, "mtp_write returning %zd\n", r);
	DBG(cdev, "%s returning %zd state:%d\n", __func__, r, dev->state);
	return r;
}

@@ -834,12 +835,15 @@ static void send_file_work(struct work_struct *data)
			break;
		}
		if (!req) {
			DBG(cdev,
				"%s request NULL ret:%d state:%d\n", __func__,
				ret, dev->state);
			r = ret;
			break;
		}

		if (count > MTP_BULK_BUFFER_SIZE)
			xfer = MTP_BULK_BUFFER_SIZE;
		if (count > mtp_tx_req_len)
			xfer = mtp_tx_req_len;
		else
			xfer = count;

@@ -891,7 +895,7 @@ static void send_file_work(struct work_struct *data)
	if (req)
		mtp_req_put(dev, &dev->tx_idle, req);

	DBG(cdev, "send_file_work returning %d\n", r);
	DBG(cdev, "%s returning %d state:%d\n", __func__, r, dev->state);
	/* write the result */
	dev->xfer_result = r;
	smp_wmb();
@@ -1048,8 +1052,10 @@ static long mtp_send_receive_ioctl(struct file *fp, unsigned int code,
	struct work_struct *work;
	int ret = -EINVAL;

	if (mtp_lock(&dev->ioctl_excl))
	if (mtp_lock(&dev->ioctl_excl)) {
		DBG(dev->cdev, "ioctl returning EBUSY state:%d\n", dev->state);
		return -EBUSY;
	}

	spin_lock_irq(&dev->lock);
	if (dev->state == STATE_CANCELED) {
@@ -1229,8 +1235,10 @@ static long compat_mtp_ioctl(struct file *fp, unsigned int code,
static int mtp_open(struct inode *ip, struct file *fp)
{
	printk(KERN_INFO "mtp_open\n");
	if (mtp_lock(&_mtp_dev->open_excl))
	if (mtp_lock(&_mtp_dev->open_excl)) {
		pr_err("%s mtp_release not called returning EBUSY\n", __func__);
		return -EBUSY;
	}

	/* clear any error condition */
	if (_mtp_dev->state != STATE_OFFLINE)
@@ -1860,6 +1868,7 @@ struct usb_function *function_alloc_mtp_ptp(struct usb_function_instance *fi,
	dev->function.disable = mtp_function_disable;
	dev->function.setup = mtp_ctrlreq_configfs;
	dev->function.free_func = mtp_free;
	fi->f = &dev->function;

	return &dev->function;
}