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

Commit 9579a43c authored by ChandanaKishori Chiluveru's avatar ChandanaKishori Chiluveru
Browse files

USB: f_serial/f_acm: Increase the IN endpoint buffer allocation



Some UDC may require allocation of some extra bytes for
the TX buffer due to hardware requirement. Add necessary
changes for the same.

Change-Id: I06bc5e5bbf154e335868bb65158bd4e03ab855e9
Signed-off-by: default avatarSujeet Kumar <ksujeet@codeaurora.org>
Signed-off-by: default avatarChandanaKishori Chiluveru <cchilu@codeaurora.org>
parent f6629052
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -788,7 +788,7 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
	/* allocate notification */
	acm->notify_req = gs_alloc_req(ep,
			sizeof(struct usb_cdc_notification) + 2,
			GFP_KERNEL);
			cdev->gadget->extra_buf_alloc, GFP_KERNEL);
	if (!acm->notify_req)
		goto fail;

+1 −1
Original line number Diff line number Diff line
@@ -835,7 +835,7 @@ static int gser_bind(struct usb_configuration *c, struct usb_function *f)
	/* allocate notification */
	gser->notify_req = gs_alloc_req(ep,
			sizeof(struct usb_cdc_notification) + 2,
			GFP_KERNEL);
			(cdev->gadget->extra_buf_alloc), GFP_KERNEL);
	if (!gser->notify_req)
		goto fail;

+9 −6
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@

#define RX_QUEUE_SIZE		8
#define RX_BUF_SIZE		4096
#define EXTRA_ALLOCATION_SIZE	256


/* circular buffer */
@@ -302,7 +303,8 @@ gs_buf_get(struct gs_buf *gb, char *buf, unsigned count)
 * usb_request or NULL if there is an error.
 */
struct usb_request *
gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
gs_alloc_req(struct usb_ep *ep, unsigned len, size_t extra_sz,
		gfp_t kmalloc_flags)
{
	struct usb_request *req;

@@ -310,7 +312,7 @@ gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)

	if (req != NULL) {
		req->length = len;
		req->buf = kmalloc(len, kmalloc_flags);
		req->buf = kmalloc(len + extra_sz, kmalloc_flags);
		if (req->buf == NULL) {
			usb_ep_free_request(ep, req);
			return NULL;
@@ -714,7 +716,7 @@ static void gs_free_requests(struct usb_ep *ep, struct list_head *head,
}

static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
		int queue_size, int req_size,
		int queue_size, int req_size, size_t extra_sz,
		void (*fn)(struct usb_ep *, struct usb_request *),
		int *allocated)
{
@@ -727,7 +729,7 @@ static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
	 * be as speedy as we might otherwise be.
	 */
	for (i = 0; i < n; i++) {
		req = gs_alloc_req(ep, req_size, GFP_ATOMIC);
		req = gs_alloc_req(ep, req_size, extra_sz, GFP_ATOMIC);
		if (!req)
			return list_empty(head) ? -ENOMEM : 0;
		req->complete = fn;
@@ -768,13 +770,14 @@ static int gs_start_io(struct gs_port *port)
	 * configurations may use different endpoints with a given port;
	 * and high speed vs full speed changes packet sizes too.
	 */
	status = gs_alloc_requests(ep, head, RX_QUEUE_SIZE, RX_BUF_SIZE,
	status = gs_alloc_requests(ep, head, RX_QUEUE_SIZE, RX_BUF_SIZE, 0,
			 gs_read_complete, &port->read_allocated);
	if (status)
		return status;

	status = gs_alloc_requests(port->port_usb->in, &port->write_pool,
			TX_QUEUE_SIZE, TX_BUF_SIZE, gs_write_complete, &port->write_allocated);
			TX_QUEUE_SIZE, TX_BUF_SIZE, EXTRA_ALLOCATION_SIZE,
			gs_write_complete, &port->write_allocated);
	if (status) {
		gs_free_requests(ep, head, &port->read_allocated);
		return status;
+2 −1
Original line number Diff line number Diff line
@@ -66,7 +66,8 @@ struct gserial {
};

/* utilities to allocate/free request and buffer */
struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len,
		size_t extra_bu_alloc, gfp_t flags);
void gs_free_req(struct usb_ep *, struct usb_request *req);

/* management of individual TTY ports */
+9 −7
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ static struct smd_portmaster {
	struct platform_driver pdrv;
} smd_ports[SMD_N_PORTS];
static unsigned n_smd_ports;
u32			extra_sz;

static void gsmd_free_req(struct usb_ep *ep, struct usb_request *req)
{
@@ -119,7 +120,7 @@ static void gsmd_free_requests(struct usb_ep *ep, struct list_head *head)
}

static struct usb_request *
gsmd_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags)
gsmd_alloc_req(struct usb_ep *ep, unsigned len, size_t extra_sz, gfp_t flags)
{
	struct usb_request *req;

@@ -130,7 +131,7 @@ gsmd_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags)
	}

	req->length = len;
	req->buf = kmalloc(len, flags);
	req->buf = kmalloc(len + extra_sz, flags);
	if (!req->buf) {
		pr_err("%s: request buf allocation failed\n", __func__);
		usb_ep_free_request(ep, req);
@@ -141,7 +142,7 @@ gsmd_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags)
}

static int gsmd_alloc_requests(struct usb_ep *ep, struct list_head *head,
		int num, int size,
		int num, int size, size_t extra_sz,
		void (*cb)(struct usb_ep *ep, struct usb_request *))
{
	int i;
@@ -151,7 +152,7 @@ static int gsmd_alloc_requests(struct usb_ep *ep, struct list_head *head,
			ep, head, num, size, cb);

	for (i = 0; i < num; i++) {
		req = gsmd_alloc_req(ep, size, GFP_ATOMIC);
		req = gsmd_alloc_req(ep, size, extra_sz, GFP_ATOMIC);
		if (!req) {
			pr_debug("%s: req allocated:%d\n", __func__, i);
			return list_empty(head) ? -ENOMEM : 0;
@@ -333,7 +334,7 @@ static void gsmd_tx_pull(struct work_struct *w)
		ret = usb_ep_queue(in, req, GFP_KERNEL);
		spin_lock_irq(&port->port_lock);
		if (ret) {
			pr_err("%s: usb ep out queue failed"
			pr_err("%s: usb ep in queue failed"
					"port:%p, port#%d err:%d\n",
					__func__, port, port->port_num, ret);
			/* could be usb disconnected */
@@ -431,7 +432,7 @@ static void gsmd_start_io(struct gsmd_port *port)

	ret = gsmd_alloc_requests(port->port_usb->out,
				&port->read_pool,
				SMD_RX_QUEUE_SIZE, SMD_RX_BUF_SIZE,
				SMD_RX_QUEUE_SIZE, SMD_RX_BUF_SIZE, 0,
				gsmd_read_complete);
	if (ret) {
		pr_err("%s: unable to allocate out requests\n",
@@ -441,7 +442,7 @@ static void gsmd_start_io(struct gsmd_port *port)

	ret = gsmd_alloc_requests(port->port_usb->in,
				&port->write_pool,
				SMD_TX_QUEUE_SIZE, SMD_TX_BUF_SIZE,
				SMD_TX_QUEUE_SIZE, SMD_TX_BUF_SIZE, extra_sz,
				gsmd_write_complete);
	if (ret) {
		gsmd_free_requests(port->port_usb->out, &port->read_pool);
@@ -977,6 +978,7 @@ int gsmd_setup(struct usb_gadget *g, unsigned count)
				__func__);
		return -ENOMEM;
	}
	extra_sz = g->extra_buf_alloc;

	for (i = 0; i < count; i++) {
		mutex_init(&smd_ports[i].lock);