Signed-off-by: Andrzej Pietrasiewicz <andrze...@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.p...@samsung.com>
---
 drivers/usb/gadget/f_mass_storage.c |  215 +---------------------------------
 drivers/usb/gadget/f_mass_storage.h |  110 ++++++++++++++++++
 2 files changed, 117 insertions(+), 208 deletions(-)
 create mode 100644 drivers/usb/gadget/f_mass_storage.h

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 5d027b3..d155115 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -229,125 +229,10 @@
 static const char fsg_string_interface[] = "Mass Storage";
 
 #include "storage_common.c"
-
+#include "f_mass_storage.h"
 
 /*-------------------------------------------------------------------------*/
 
-struct fsg_dev;
-struct fsg_common;
-
-/* FSF callback functions */
-struct fsg_operations {
-       /*
-        * Callback function to call when thread exits.  If no
-        * callback is set or it returns value lower then zero MSF
-        * will force eject all LUNs it operates on (including those
-        * marked as non-removable or with prevent_medium_removal flag
-        * set).
-        */
-       int (*thread_exits)(struct fsg_common *common);
-
-       /*
-        * Called prior to ejection.  Negative return means error,
-        * zero means to continue with ejection, positive means not to
-        * eject.
-        */
-       int (*pre_eject)(struct fsg_common *common,
-                        struct fsg_lun *lun, int num);
-       /*
-        * Called after ejection.  Negative return means error, zero
-        * or positive is just a success.
-        */
-       int (*post_eject)(struct fsg_common *common,
-                         struct fsg_lun *lun, int num);
-};
-
-/* Data shared by all the FSG instances. */
-struct fsg_common {
-       struct usb_gadget       *gadget;
-       struct usb_composite_dev *cdev;
-       struct fsg_dev          *fsg, *new_fsg;
-       wait_queue_head_t       fsg_wait;
-
-       /* filesem protects: backing files in use */
-       struct rw_semaphore     filesem;
-
-       /* lock protects: state, all the req_busy's */
-       spinlock_t              lock;
-
-       struct usb_ep           *ep0;           /* Copy of gadget->ep0 */
-       struct usb_request      *ep0req;        /* Copy of cdev->req */
-       unsigned int            ep0_req_tag;
-
-       struct fsg_buffhd       *next_buffhd_to_fill;
-       struct fsg_buffhd       *next_buffhd_to_drain;
-       struct fsg_buffhd       *buffhds;
-
-       int                     cmnd_size;
-       u8                      cmnd[MAX_COMMAND_SIZE];
-
-       unsigned int            nluns;
-       unsigned int            lun;
-       struct fsg_lun          *luns;
-       struct fsg_lun          *curlun;
-
-       unsigned int            bulk_out_maxpacket;
-       enum fsg_state          state;          /* For exception handling */
-       unsigned int            exception_req_tag;
-
-       enum data_direction     data_dir;
-       u32                     data_size;
-       u32                     data_size_from_cmnd;
-       u32                     tag;
-       u32                     residue;
-       u32                     usb_amount_left;
-
-       unsigned int            can_stall:1;
-       unsigned int            free_storage_on_release:1;
-       unsigned int            phase_error:1;
-       unsigned int            short_packet_received:1;
-       unsigned int            bad_lun_okay:1;
-       unsigned int            running:1;
-
-       int                     thread_wakeup_needed;
-       struct completion       thread_notifier;
-       struct task_struct      *thread_task;
-
-       /* Callback functions. */
-       const struct fsg_operations     *ops;
-       /* Gadget's private data. */
-       void                    *private_data;
-
-       /*
-        * Vendor (8 chars), product (16 chars), release (4
-        * hexadecimal digits) and NUL byte
-        */
-       char inquiry_string[8 + 16 + 4 + 1];
-
-       struct kref             ref;
-};
-
-struct fsg_config {
-       unsigned nluns;
-       struct fsg_lun_config {
-               const char *filename;
-               char ro;
-               char removable;
-               char cdrom;
-               char nofua;
-       } luns[FSG_MAX_LUNS];
-
-       /* Callback functions. */
-       const struct fsg_operations     *ops;
-       /* Gadget's private data. */
-       void                    *private_data;
-
-       const char *vendor_name;                /*  8 characters or less */
-       const char *product_name;               /* 16 characters or less */
-
-       char                    can_stall;
-};
-
 struct fsg_dev {
        struct usb_function     function;
        struct usb_gadget       *gadget;        /* Copy of cdev->gadget */
@@ -2622,17 +2507,19 @@ static void fsg_lun_release(struct device *dev)
        /* Nothing needs to be done */
 }
 
-static inline void fsg_common_get(struct fsg_common *common)
+void fsg_common_get(struct fsg_common *common)
 {
        kref_get(&common->ref);
 }
+EXPORT_SYMBOL(fsg_common_get);
 
-static inline void fsg_common_put(struct fsg_common *common)
+void fsg_common_put(struct fsg_common *common)
 {
        kref_put(&common->ref, fsg_common_release);
 }
+EXPORT_SYMBOL(fsg_common_put);
 
-static struct fsg_common *fsg_common_init(struct fsg_common *common,
+struct fsg_common *fsg_common_init(struct fsg_common *common,
                                          struct usb_composite_dev *cdev,
                                          struct fsg_config *cfg)
 {
@@ -2837,6 +2724,7 @@ error_release:
        fsg_common_release(&common->ref);
        return ERR_PTR(rc);
 }
+EXPORT_SYMBOL(fsg_common_init);
 
 static void fsg_common_release(struct kref *ref)
 {
@@ -3007,92 +2895,3 @@ static int fsg_bind_config(struct usb_composite_dev 
*cdev,
        return rc;
 }
 
-
-/************************* Module parameters *************************/
-
-struct fsg_module_parameters {
-       char            *file[FSG_MAX_LUNS];
-       bool            ro[FSG_MAX_LUNS];
-       bool            removable[FSG_MAX_LUNS];
-       bool            cdrom[FSG_MAX_LUNS];
-       bool            nofua[FSG_MAX_LUNS];
-
-       unsigned int    file_count, ro_count, removable_count, cdrom_count;
-       unsigned int    nofua_count;
-       unsigned int    luns;   /* nluns */
-       bool            stall;  /* can_stall */
-};
-
-#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)      \
-       module_param_array_named(prefix ## name, params.name, type,     \
-                                &prefix ## params.name ## _count,      \
-                                S_IRUGO);                              \
-       MODULE_PARM_DESC(prefix ## name, desc)
-
-#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)            \
-       module_param_named(prefix ## name, params.name, type,           \
-                          S_IRUGO);                                    \
-       MODULE_PARM_DESC(prefix ## name, desc)
-
-#define FSG_MODULE_PARAMETERS(prefix, params)                          \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp,            \
-                               "names of backing files or devices");   \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool,               \
-                               "true to force read-only");             \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool,        \
-                               "true to simulate removable media");    \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool,            \
-                               "true to simulate CD-ROM instead of disk"); \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool,            \
-                               "true to ignore SCSI WRITE(10,12) FUA bit"); \
-       _FSG_MODULE_PARAM(prefix, params, luns, uint,                   \
-                         "number of LUNs");                            \
-       _FSG_MODULE_PARAM(prefix, params, stall, bool,                  \
-                         "false to prevent bulk stalls")
-
-static void
-fsg_config_from_params(struct fsg_config *cfg,
-                      const struct fsg_module_parameters *params)
-{
-       struct fsg_lun_config *lun;
-       unsigned i;
-
-       /* Configure LUNs */
-       cfg->nluns =
-               min(params->luns ?: (params->file_count ?: 1u),
-                   (unsigned)FSG_MAX_LUNS);
-       for (i = 0, lun = cfg->luns; i < cfg->nluns; ++i, ++lun) {
-               lun->ro = !!params->ro[i];
-               lun->cdrom = !!params->cdrom[i];
-               lun->removable = !!params->removable[i];
-               lun->filename =
-                       params->file_count > i && params->file[i][0]
-                       ? params->file[i]
-                       : 0;
-       }
-
-       /* Let MSF use defaults */
-       cfg->vendor_name = 0;
-       cfg->product_name = 0;
-
-       cfg->ops = NULL;
-       cfg->private_data = NULL;
-
-       /* Finalise */
-       cfg->can_stall = params->stall;
-}
-
-static inline struct fsg_common *
-fsg_common_from_params(struct fsg_common *common,
-                      struct usb_composite_dev *cdev,
-                      const struct fsg_module_parameters *params)
-       __attribute__((unused));
-static inline struct fsg_common *
-fsg_common_from_params(struct fsg_common *common,
-                      struct usb_composite_dev *cdev,
-                      const struct fsg_module_parameters *params)
-{
-       struct fsg_config cfg;
-       fsg_config_from_params(&cfg, params);
-       return fsg_common_init(common, cdev, &cfg);
-}
diff --git a/drivers/usb/gadget/f_mass_storage.h 
b/drivers/usb/gadget/f_mass_storage.h
new file mode 100644
index 0000000..9f8d47e
--- /dev/null
+++ b/drivers/usb/gadget/f_mass_storage.h
@@ -0,0 +1,110 @@
+#ifndef F_MASS_STORAGE_H
+#define F_MASS_STORAGE_H
+
+#include "storage_common.h"
+
+struct fsg_common;
+struct fsg_operations;
+struct usb_composite_dev;
+struct fsg_dev;
+struct fsg_lun;
+
+/* FSF callback functions */
+struct fsg_operations {
+       /*
+        * Callback function to call when thread exits.  If no
+        * callback is set or it returns value lower then zero MSF
+        * will force eject all LUNs it operates on (including those
+        * marked as non-removable or with prevent_medium_removal flag
+        * set).
+        */
+       int (*thread_exits)(struct fsg_common *common);
+
+       /*
+        * Called prior to ejection.  Negative return means error,
+        * zero means to continue with ejection, positive means not to
+        * eject.
+        */
+       int (*pre_eject)(struct fsg_common *common,
+                        struct fsg_lun *lun, int num);
+       /*
+        * Called after ejection.  Negative return means error, zero
+        * or positive is just a success.
+        */
+       int (*post_eject)(struct fsg_common *common,
+                         struct fsg_lun *lun, int num);
+};
+
+/* Data shared by all the FSG instances. */
+struct fsg_common {
+       struct usb_gadget       *gadget;
+       struct usb_composite_dev *cdev;
+       struct fsg_dev          *fsg, *new_fsg;
+       wait_queue_head_t       fsg_wait;
+
+       /* filesem protects: backing files in use */
+       struct rw_semaphore     filesem;
+
+       /* lock protects: state, all the req_busy's */
+       spinlock_t              lock;
+
+       struct usb_ep           *ep0;           /* Copy of gadget->ep0 */
+       struct usb_request      *ep0req;        /* Copy of cdev->req */
+       unsigned int            ep0_req_tag;
+
+       struct fsg_buffhd       *next_buffhd_to_fill;
+       struct fsg_buffhd       *next_buffhd_to_drain;
+       struct fsg_buffhd       *buffhds;
+
+       int                     cmnd_size;
+       u8                      cmnd[MAX_COMMAND_SIZE];
+
+       unsigned int            nluns;
+       unsigned int            lun;
+       struct fsg_lun          *luns;
+       struct fsg_lun          *curlun;
+
+       unsigned int            bulk_out_maxpacket;
+       enum fsg_state          state;          /* For exception handling */
+       unsigned int            exception_req_tag;
+
+       enum data_direction     data_dir;
+       u32                     data_size;
+       u32                     data_size_from_cmnd;
+       u32                     tag;
+       u32                     residue;
+       u32                     usb_amount_left;
+
+       unsigned int            can_stall:1;
+       unsigned int            free_storage_on_release:1;
+       unsigned int            phase_error:1;
+       unsigned int            short_packet_received:1;
+       unsigned int            bad_lun_okay:1;
+       unsigned int            running:1;
+
+       int                     thread_wakeup_needed;
+       struct completion       thread_notifier;
+       struct task_struct      *thread_task;
+
+       /* Callback functions. */
+       const struct fsg_operations     *ops;
+       /* Gadget's private data. */
+       void                    *private_data;
+
+       /*
+        * Vendor (8 chars), product (16 chars), release (4
+        * hexadecimal digits) and NUL byte
+        */
+       char inquiry_string[8 + 16 + 4 + 1];
+
+       struct kref             ref;
+};
+
+struct fsg_common *fsg_common_init(struct fsg_common *common,
+                                         struct usb_composite_dev *cdev,
+                                         struct fsg_config *cfg);
+
+void fsg_common_get(struct fsg_common *common);
+void fsg_common_put(struct fsg_common *common);
+
+#endif
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to