A storage_common2.c file created with functions which require definition of storage instance structure. Signed-off-by: Michal Nazarewicz <mnazarewicz@xxxxxxxxxxx> --- drivers/usb/gadget/f_mass_storage.c | 60 +++------------------- drivers/usb/gadget/file_storage.c | 89 ++++----------------------------- drivers/usb/gadget/storage_common2.c | 92 ++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 131 deletions(-) create mode 100644 drivers/usb/gadget/storage_common2.c diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 3c523d3..c245ce9 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -393,9 +393,13 @@ struct msf { u32 tag; u32 residue; u32 usb_amount_left; - }; + +typedef struct msf storage_instance; +#include "storage_common2.c" + + typedef void (*msf_routine_t)(struct msf *); static int msf_exception_in_progress(struct msf *msf) @@ -542,7 +546,7 @@ static int msf_populate_config_buf(struct usb_gadget *gadget, /* These routines may be called in process context or in_irq */ /* Caller must hold msf->lock */ -static void msf_wakeup_thread(struct msf *msf) +static void stor_wakeup_thread(struct msf *msf) { /* Tell the main thread that something has happened */ msf->thread_wakeup_needed = 1; @@ -619,54 +623,6 @@ static void msf_ep0_complete(struct usb_ep *ep, struct usb_request *req) /*-------------------------------------------------------------------------*/ -/* Bulk and interrupt endpoint completion handlers. - * These always run in_irq. */ - -static void msf_bulk_in_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct msf *msf = ep->driver_data; - struct stor_buffhd *bh = req->context; - - if (req->status || req->actual != req->length) - SDBG(msf, "%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(&msf->lock); - bh->inreq_busy = 0; - bh->state = BUF_STATE_EMPTY; - msf_wakeup_thread(msf); - spin_unlock(&msf->lock); -} - -static void msf_bulk_out_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct msf *msf = ep->driver_data; - struct stor_buffhd *bh = req->context; - - dump_msg(msf, "bulk-out", req->buf, req->actual); - if (req->status || req->actual != bh->bulk_out_intended_length) - SDBG(msf, "%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(&msf->lock); - bh->outreq_busy = 0; - bh->state = BUF_STATE_FULL; - msf_wakeup_thread(msf); - spin_unlock(&msf->lock); -} - - -/*-------------------------------------------------------------------------*/ - /* Ep0 class-specific handlers. These always run in_irq. */ static int msf_class_setup_req(struct msf *msf, @@ -2518,8 +2474,8 @@ reset: goto reset; bh->inreq->buf = bh->outreq->buf = bh->buf; bh->inreq->context = bh->outreq->context = bh; - bh->inreq->complete = msf_bulk_in_complete; - bh->outreq->complete = msf_bulk_out_complete; + bh->inreq->complete = stor_bulk_in_complete; + bh->outreq->complete = stor_bulk_out_complete; } msf->running = 1; diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index d1d463c..af480ef 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -480,6 +480,11 @@ struct fsg_dev { struct storage_lun *curlun; }; + +typedef struct fsg_dev storage_instance; +#include "storage_common2.c" + + typedef void (*fsg_routine_t)(struct fsg_dev *); static int exception_in_progress(struct fsg_dev *fsg) @@ -487,6 +492,7 @@ static int exception_in_progress(struct fsg_dev *fsg) return (fsg->state > STOR_STATE_IDLE); } + /* Make bulk-out requests be divisible by the maxpacket size */ static void set_bulk_out_req_length(struct fsg_dev *fsg, struct stor_buffhd *bh, unsigned int length) @@ -626,7 +632,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 stor_wakeup_thread(struct fsg_dev *fsg) { /* Tell the main thread that something has happened */ fsg->thread_wakeup_needed = 1; @@ -703,81 +709,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 stor_buffhd *bh = req->context; - - if (req->status || req->actual != req->length) - SDBG(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 stor_buffhd *bh = req->context; - - dump_msg(fsg, "bulk-out", req->buf, req->actual); - if (req->status || req->actual != bh->bulk_out_intended_length) - SDBG(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 stor_buffhd *bh = req->context; - - if (req->status || req->actual != req->length) - SDBG(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 @@ -2844,13 +2775,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 = stor_bulk_in_complete; + bh->outreq->complete = stor_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 = stor_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..b844d66 --- /dev/null +++ b/drivers/usb/gadget/storage_common2.c @@ -0,0 +1,92 @@ +/* + * 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 storage_instance type to be defined which is + * a structure containing lock field (being a spinlock). Also, + * stor_wakeup_thread() function needs to be defined prior or after + * including this file. + */ + + +static void stor_wakeup_thread(storage_instance *instance); + + +/*-------------------------------------------------------------------------*/ + +/* Bulk and interrupt endpoint completion handlers. + * These always run in_irq. */ + +static void stor__complete(struct usb_ep *ep, struct usb_request *req, + unsigned length, int *flag, int new_state) +{ + storage_instance *stor = ep->driver_data; + struct stor_buffhd *bh = req->context; + + /* Strange status or length */ + if (req->status || req->actual != length) + SDBG(stor, "%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(&stor->lock); + *flag = 0; + bh->state = new_state; + stor_wakeup_thread(stor); + spin_unlock(&stor->lock); +} + + +static void stor_bulk_in_complete(struct usb_ep *ep, + struct usb_request *req) +{ + struct stor_buffhd *bh = req->context; + stor__complete(ep, req, req->length, + &bh->inreq_busy, BUF_STATE_EMPTY); +} + +static void stor_bulk_out_complete(struct usb_ep *ep, + struct usb_request *req) +{ + struct stor_buffhd *bh = req->context; + stor__complete(ep, req, bh->bulk_out_intended_length, + &bh->outreq_busy, BUF_STATE_FULL); +} + + +#ifdef STOR_DESCRIPTORS_INTR_EP +static void stor_intr_in_complete(struct usb_ep *ep, + struct usb_request *req) +{ +# ifdef CONFIG_USB_FILE_STORAGE_TEST + struct stor_buffhd *bh = req->context; + stor__complete(ep, req, req->length, + &bh->intreq_busy, BUF_STATE_EMPTY); +# endif /* CONFIG_USB_FILE_STORAGE_TEST */ +} +#endif /* STOR_DESCRIPTORS_INTR_EP */ -- 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