A storage_common2.c file created with functions which require definition of fsg_dev structure. It was not possible to move those to storage_common.c file because storage_common.c is included prior to defining fsg_dev structure. Signed-off-by: Michal Nazarewicz <m.nazarewicz@xxxxxxxxxxx> --- drivers/usb/gadget/file_storage.c | 88 +++-------------------------- drivers/usb/gadget/storage_common2.c | 102 ++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 79 deletions(-) create mode 100644 drivers/usb/gadget/storage_common2.c diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 9b96bd2..a6d7af8 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -479,6 +479,10 @@ struct fsg_dev { struct fsg_lun *curlun; }; + +#include "storage_common2.c" + + typedef void (*fsg_routine_t)(struct fsg_dev *); static int exception_in_progress(struct fsg_dev *fsg) @@ -486,6 +490,7 @@ static int exception_in_progress(struct fsg_dev *fsg) return (fsg->state > FSG_STATE_IDLE); } + /* Make bulk-out requests be divisible by the maxpacket size */ static void set_bulk_out_req_length(struct fsg_dev *fsg, struct fsg_buffhd *bh, unsigned int length) @@ -630,7 +635,7 @@ static int populate_config_buf(struct usb_gadget *gadget, /* These routines may be called in process context or in_irq */ /* Caller must hold fsg->lock */ -static void wakeup_thread(struct fsg_dev *fsg) +static void fsg_wakeup_thread(struct fsg_dev *fsg) { /* Tell the main thread that something has happened */ fsg->thread_wakeup_needed = 1; @@ -707,81 +712,6 @@ static void ep0_complete(struct usb_ep *ep, struct usb_request *req) /*-------------------------------------------------------------------------*/ -/* Bulk and interrupt endpoint completion handlers. - * These always run in_irq. */ - -static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct fsg_dev *fsg = ep->driver_data; - struct fsg_buffhd *bh = req->context; - - if (req->status || req->actual != req->length) - DBG(fsg, "%s --> %d, %u/%u\n", __func__, - req->status, req->actual, req->length); - if (req->status == -ECONNRESET) // Request was cancelled - usb_ep_fifo_flush(ep); - - /* Hold the lock while we update the request and buffer states */ - smp_wmb(); - spin_lock(&fsg->lock); - bh->inreq_busy = 0; - bh->state = BUF_STATE_EMPTY; - wakeup_thread(fsg); - spin_unlock(&fsg->lock); -} - -static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct fsg_dev *fsg = ep->driver_data; - struct fsg_buffhd *bh = req->context; - - dump_msg(fsg, "bulk-out", req->buf, req->actual); - if (req->status || req->actual != bh->bulk_out_intended_length) - DBG(fsg, "%s --> %d, %u/%u\n", __func__, - req->status, req->actual, - bh->bulk_out_intended_length); - if (req->status == -ECONNRESET) // Request was cancelled - usb_ep_fifo_flush(ep); - - /* Hold the lock while we update the request and buffer states */ - smp_wmb(); - spin_lock(&fsg->lock); - bh->outreq_busy = 0; - bh->state = BUF_STATE_FULL; - wakeup_thread(fsg); - spin_unlock(&fsg->lock); -} - - -#ifdef CONFIG_USB_FILE_STORAGE_TEST -static void intr_in_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct fsg_dev *fsg = ep->driver_data; - struct fsg_buffhd *bh = req->context; - - if (req->status || req->actual != req->length) - DBG(fsg, "%s --> %d, %u/%u\n", __func__, - req->status, req->actual, req->length); - if (req->status == -ECONNRESET) // Request was cancelled - usb_ep_fifo_flush(ep); - - /* Hold the lock while we update the request and buffer states */ - smp_wmb(); - spin_lock(&fsg->lock); - fsg->intreq_busy = 0; - bh->state = BUF_STATE_EMPTY; - wakeup_thread(fsg); - spin_unlock(&fsg->lock); -} - -#else -static void intr_in_complete(struct usb_ep *ep, struct usb_request *req) -{} -#endif /* CONFIG_USB_FILE_STORAGE_TEST */ - - -/*-------------------------------------------------------------------------*/ - /* Ep0 class-specific handlers. These always run in_irq. */ #ifdef CONFIG_USB_FILE_STORAGE_TEST @@ -2849,13 +2779,13 @@ reset: goto reset; bh->inreq->buf = bh->outreq->buf = bh->buf; bh->inreq->context = bh->outreq->context = bh; - bh->inreq->complete = bulk_in_complete; - bh->outreq->complete = bulk_out_complete; + bh->inreq->complete = fsg_bulk_in_complete; + bh->outreq->complete = fsg_bulk_out_complete; } if (transport_is_cbi()) { if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0) goto reset; - fsg->intreq->complete = intr_in_complete; + fsg->intreq->complete = fsg_intr_in_complete; } fsg->running = 1; diff --git a/drivers/usb/gadget/storage_common2.c b/drivers/usb/gadget/storage_common2.c new file mode 100644 index 0000000..3603bcf --- /dev/null +++ b/drivers/usb/gadget/storage_common2.c @@ -0,0 +1,102 @@ +/* + * storage_common2.c -- Common definitions for mass storage functionality. + * + * Copyright (C) 2003-2008 Alan Stern + * Copyeight (C) 2009 Samsung Electronics + * Author: Michal Nazarewicz (m.nazarewicz@xxxxxxxxxxx) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * This file requires struct fsg_dev type to be defined which is + * a structure containing lock field (being a spinlock). Also, + * fsg_wakeup_thread() function needs to be defined prior or after + * including this file. + */ + + +static void fsg_wakeup_thread(struct fsg_dev *fsg); + + +/*-------------------------------------------------------------------------*/ + +/* Bulk and interrupt endpoint completion handlers. + * These always run in_irq. */ + +static void fsg__complete(struct usb_ep *ep, struct usb_request *req, + unsigned length, int *flag, int new_state) +{ + struct fsg_dev *fsg = ep->driver_data; + struct fsg_buffhd *bh = req->context; + + /* Strange status or length */ + if (req->status || req->actual != length) + DBG(fsg, "%s --> %d, %u/%u\n", __func__, + req->status, req->actual, length); + + /* Request was canceled */ + if (req->status == -ECONNRESET) + usb_ep_fifo_flush(ep); + + /* Hold the lock while we update the request and buffer + * states */ + smp_wmb(); + spin_lock(&fsg->lock); + *flag = 0; + bh->state = new_state; + fsg_wakeup_thread(fsg); + spin_unlock(&fsg->lock); +} + + +static void fsg_bulk_in_complete(struct usb_ep *ep, + struct usb_request *req) +{ + struct fsg_buffhd *bh = req->context; + fsg__complete(ep, req, req->length, + &bh->inreq_busy, BUF_STATE_EMPTY); +} + +static void fsg_bulk_out_complete(struct usb_ep *ep, + struct usb_request *req) +{ + struct fsg_buffhd *bh = req->context; + fsg__complete(ep, req, bh->bulk_out_intended_length, + &bh->outreq_busy, BUF_STATE_FULL); +} + + +#ifndef FSG_NO_INTR_EP + +# ifdef CONFIG_USB_FILE_STORAGE_TEST + +static void fsg_intr_in_complete(struct usb_ep *ep, + struct usb_request *req) +{ + struct fsg_buffhd *bh = req->context; + fsg__complete(ep, req, req->length, + &bh->intreq_busy, BUF_STATE_EMPTY); +} + +# else /* CONFIG_USB_FILE_STORAGE_TEST */ + +static void fsg_intr_in_complete(struct usb_ep *ep, + struct usb_request *req) +{ } + +# endif /* CONFIG_USB_FILE_STORAGE_TEST */ + +#endif /* FSG_DESCRIPTORS_INTR_EP */ -- 1.6.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html