Revert "usb/gadget: create a utility module for mass_storage"
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Tue, 14 Jan 2014 13:28:02 +0000 (14:28 +0100)
committerChanho Park <chanho61.park@samsung.com>
Tue, 18 Nov 2014 02:46:16 +0000 (11:46 +0900)
This reverts commit 999eab4c72b5afbb59bdb5668a03118ea79e4455.

drivers/usb/gadget/Kconfig
drivers/usb/gadget/Makefile
drivers/usb/gadget/acm_ms.c
drivers/usb/gadget/f_mass_storage.c
drivers/usb/gadget/mass_storage.c
drivers/usb/gadget/multi.c
drivers/usb/gadget/storage_common.c
drivers/usb/gadget/storage_common.h [deleted file]

index ecfcbab..8205354 100644 (file)
@@ -537,9 +537,6 @@ config USB_F_SUBSET
 config USB_F_RNDIS
        tristate
 
-config USB_U_MS
-       tristate
-
 choice
        tristate "USB Gadget Drivers"
        default USB_ETH
@@ -893,7 +890,6 @@ config USB_MASS_STORAGE
        tristate "Mass Storage Gadget"
        depends on BLOCK
        select USB_LIBCOMPOSITE
-       select USB_U_MS
        help
          The Mass Storage Gadget acts as a USB Mass Storage disk drive.
          As its storage repository it can use a regular file or a block
@@ -1029,7 +1025,6 @@ config USB_G_ACM_MS
        select USB_LIBCOMPOSITE
        select USB_U_SERIAL
        select USB_F_ACM
-       select USB_U_MS
        help
          This driver provides two functions in one configuration:
          a mass storage, and a CDC ACM (serial port) link.
@@ -1046,7 +1041,6 @@ config USB_G_MULTI
        select USB_U_ETHER
        select USB_U_RNDIS
        select USB_F_ACM
-       select USB_U_MS
        help
          The Multifunction Composite Gadget provides Ethernet (RNDIS
          and/or CDC Ethernet), mass storage and ACM serial link
index 295df78..0becdfa 100644 (file)
@@ -60,8 +60,6 @@ usb_f_ecm_subset-y            := f_subset.o
 obj-$(CONFIG_USB_F_SUBSET)     += usb_f_ecm_subset.o
 usb_f_rndis-y                  := f_rndis.o
 obj-$(CONFIG_USB_F_RNDIS)      += usb_f_rndis.o
-u_ms-y                         := storage_common.o
-obj-$(CONFIG_USB_U_MS)         += u_ms.o
 
 #
 # USB gadget drivers
index 992ffb0..4b947bb 100644 (file)
@@ -104,20 +104,6 @@ static struct usb_gadget_strings *dev_strings[] = {
 /****************************** Configurations ******************************/
 
 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
-
-#else
-
-/*
- * Number of buffers we will use.
- * 2 is usually enough for good buffering pipeline
- */
-#define fsg_num_buffers        CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
-
-#endif /* CONFIG_USB_DEBUG */
-
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
 static struct fsg_common fsg_common;
@@ -181,8 +167,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
        void                    *retp;
 
        /* set up mass storage function */
-       retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data,
-                                     fsg_num_buffers);
+       retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
        if (IS_ERR(retp)) {
                status = PTR_ERR(retp);
                return PTR_ERR(retp);
index 163d911..56f1fd1 100644 (file)
 
 static const char fsg_string_interface[] = "Mass Storage";
 
-#include "storage_common.h"
+#include "storage_common.c"
 
-/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
-static struct usb_string               fsg_strings[] = {
-       {FSG_STRING_INTERFACE,          fsg_string_interface},
-       {}
-};
-
-static struct usb_gadget_strings       fsg_stringtab = {
-       .language       = 0x0409,               /* en-us */
-       .strings        = fsg_strings,
-};
 
 /*-------------------------------------------------------------------------*/
 
@@ -278,7 +268,6 @@ struct fsg_common {
        struct fsg_buffhd       *next_buffhd_to_fill;
        struct fsg_buffhd       *next_buffhd_to_drain;
        struct fsg_buffhd       *buffhds;
-       unsigned int            fsg_num_buffers;
 
        int                     cmnd_size;
        u8                      cmnd[MAX_COMMAND_SIZE];
@@ -343,7 +332,6 @@ struct fsg_config {
        const char *product_name;               /* 16 characters or less */
 
        char                    can_stall;
-       unsigned int            fsg_num_buffers;
 };
 
 struct fsg_dev {
@@ -2256,7 +2244,7 @@ reset:
        if (common->fsg) {
                fsg = common->fsg;
 
-               for (i = 0; i < common->fsg_num_buffers; ++i) {
+               for (i = 0; i < fsg_num_buffers; ++i) {
                        struct fsg_buffhd *bh = &common->buffhds[i];
 
                        if (bh->inreq) {
@@ -2313,7 +2301,7 @@ reset:
        clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
 
        /* Allocate the requests */
-       for (i = 0; i < common->fsg_num_buffers; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                struct fsg_buffhd       *bh = &common->buffhds[i];
 
                rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
@@ -2382,7 +2370,7 @@ static void handle_exception(struct fsg_common *common)
 
        /* Cancel all the pending transfers */
        if (likely(common->fsg)) {
-               for (i = 0; i < common->fsg_num_buffers; ++i) {
+               for (i = 0; i < fsg_num_buffers; ++i) {
                        bh = &common->buffhds[i];
                        if (bh->inreq_busy)
                                usb_ep_dequeue(common->fsg->bulk_in, bh->inreq);
@@ -2394,7 +2382,7 @@ static void handle_exception(struct fsg_common *common)
                /* Wait until everything is idle */
                for (;;) {
                        int num_active = 0;
-                       for (i = 0; i < common->fsg_num_buffers; ++i) {
+                       for (i = 0; i < fsg_num_buffers; ++i) {
                                bh = &common->buffhds[i];
                                num_active += bh->inreq_busy + bh->outreq_busy;
                        }
@@ -2417,7 +2405,7 @@ static void handle_exception(struct fsg_common *common)
         */
        spin_lock_irq(&common->lock);
 
-       for (i = 0; i < common->fsg_num_buffers; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                bh = &common->buffhds[i];
                bh->state = BUF_STATE_EMPTY;
        }
@@ -2619,16 +2607,6 @@ static inline void fsg_common_put(struct fsg_common *common)
        kref_put(&common->ref, fsg_common_release);
 }
 
-/* check if fsg_num_buffers is within a valid range */
-static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
-{
-       if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
-               return 0;
-       pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
-              fsg_num_buffers, 2, 4);
-       return -EINVAL;
-}
-
 static struct fsg_common *fsg_common_init(struct fsg_common *common,
                                          struct usb_composite_dev *cdev,
                                          struct fsg_config *cfg)
@@ -2640,7 +2618,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
        int nluns, i, rc;
        char *pathbuf;
 
-       rc = fsg_num_buffers_validate(cfg->fsg_num_buffers);
+       rc = fsg_num_buffers_validate();
        if (rc != 0)
                return ERR_PTR(rc);
 
@@ -2662,8 +2640,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
                common->free_storage_on_release = 0;
        }
 
-       common->fsg_num_buffers = cfg->fsg_num_buffers;
-       common->buffhds = kcalloc(common->fsg_num_buffers,
+       common->buffhds = kcalloc(fsg_num_buffers,
                                  sizeof *(common->buffhds), GFP_KERNEL);
        if (!common->buffhds) {
                if (common->free_storage_on_release)
@@ -2750,7 +2727,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 
        /* Data buffers cyclic list */
        bh = common->buffhds;
-       i = common->fsg_num_buffers;
+       i = fsg_num_buffers;
        goto buffhds_first_it;
        do {
                bh->next = bh + 1;
@@ -2870,7 +2847,7 @@ static void fsg_common_release(struct kref *ref)
 
        {
                struct fsg_buffhd *bh = common->buffhds;
-               unsigned i = common->fsg_num_buffers;
+               unsigned i = fsg_num_buffers;
                do {
                        kfree(bh->buf);
                } while (++bh, --i);
@@ -3032,7 +3009,7 @@ struct fsg_module_parameters {
                           S_IRUGO);                                    \
        MODULE_PARM_DESC(prefix ## name, desc)
 
-#define __FSG_MODULE_PARAMETERS(prefix, params)                                \
+#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,               \
@@ -3048,24 +3025,9 @@ struct fsg_module_parameters {
        _FSG_MODULE_PARAM(prefix, params, stall, bool,                  \
                          "false to prevent bulk stalls")
 
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-#define FSG_MODULE_PARAMETERS(prefix, params)                          \
-       __FSG_MODULE_PARAMETERS(prefix, params);                        \
-       module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
-       MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
-#else
-
-#define FSG_MODULE_PARAMETERS(prefix, params)                          \
-       __FSG_MODULE_PARAMETERS(prefix, params)
-
-#endif
-
-
 static void
 fsg_config_from_params(struct fsg_config *cfg,
-                      const struct fsg_module_parameters *params,
-                      unsigned int fsg_num_buffers)
+                      const struct fsg_module_parameters *params)
 {
        struct fsg_lun_config *lun;
        unsigned i;
@@ -3093,22 +3055,19 @@ fsg_config_from_params(struct fsg_config *cfg,
 
        /* Finalise */
        cfg->can_stall = params->stall;
-       cfg->fsg_num_buffers = fsg_num_buffers;
 }
 
 static inline struct fsg_common *
 fsg_common_from_params(struct fsg_common *common,
                       struct usb_composite_dev *cdev,
-                      const struct fsg_module_parameters *params,
-                      unsigned int fsg_num_buffers)
+                      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,
-                      unsigned int fsg_num_buffers)
+                      const struct fsg_module_parameters *params)
 {
        struct fsg_config cfg;
-       fsg_config_from_params(&cfg, params, fsg_num_buffers);
+       fsg_config_from_params(&cfg, params);
        return fsg_common_init(common, cdev, &cfg);
 }
index bf60a9a..080e577 100644 (file)
 #define DRIVER_DESC            "Mass Storage Gadget"
 #define DRIVER_VERSION         "2009/09/11"
 
-/*
- * Thanks to NetChip Technologies for donating this product ID.
- *
- * DO NOT REUSE THESE IDs with any other driver!!  Ever!!
- * Instead:  allocate your own, using normal USB-IF procedures.
- */
-#define FSG_VENDOR_ID  0x0525  /* NetChip */
-#define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
-
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -111,20 +102,6 @@ static struct usb_gadget_strings *dev_strings[] = {
 static struct fsg_module_parameters mod_data = {
        .stall = 1
 };
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
-
-#else
-
-/*
- * Number of buffers we will use.
- * 2 is usually enough for good buffering pipeline
- */
-#define fsg_num_buffers        CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
-
-#endif /* CONFIG_USB_DEBUG */
-
 FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
 
 static unsigned long msg_registered;
@@ -152,7 +129,7 @@ static int __init msg_do_config(struct usb_configuration *c)
                c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
        }
 
-       fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
+       fsg_config_from_params(&config, &mod_data);
        config.ops = &ops;
 
        retp = fsg_common_init(&common, c->cdev, &config);
index f610d01..2a1ebef 100644 (file)
@@ -132,20 +132,6 @@ static struct usb_gadget_strings *dev_strings[] = {
 /****************************** Configurations ******************************/
 
 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
-
-#else
-
-/*
- * Number of buffers we will use.
- * 2 is usually enough for good buffering pipeline
- */
-#define fsg_num_buffers        CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
-
-#endif /* CONFIG_USB_DEBUG */
-
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
 static struct fsg_common fsg_common;
@@ -308,8 +294,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
        /* set up mass storage function */
        {
                void *retp;
-               retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data,
-                                             fsg_num_buffers);
+               retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
                if (IS_ERR(retp)) {
                        status = PTR_ERR(retp);
                        goto fail1;
index 942324c..dbce3a9 100644 (file)
  * The valid range of num_buffers is: num >= 2 && num <= 4.
  */
 
-#include <linux/module.h>
-#include <linux/blkdev.h>
-#include <linux/file.h>
-#include <linux/fs.h>
-#include <linux/usb/composite.h>
 
-#include "storage_common.h"
+#include <linux/usb/storage.h>
+#include <scsi/scsi.h>
+#include <asm/unaligned.h>
+
+
+/*
+ * Thanks to NetChip Technologies for donating this product ID.
+ *
+ * DO NOT REUSE THESE IDs with any other driver!!  Ever!!
+ * Instead:  allocate your own, using normal USB-IF procedures.
+ */
+#define FSG_VENDOR_ID  0x0525  /* NetChip */
+#define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
+
+
+/*-------------------------------------------------------------------------*/
+
+
+#ifndef DEBUG
+#undef VERBOSE_DEBUG
+#undef DUMP_MSGS
+#endif /* !DEBUG */
+
+#ifdef VERBOSE_DEBUG
+#define VLDBG  LDBG
+#else
+#define VLDBG(lun, fmt, args...) do { } while (0)
+#endif /* VERBOSE_DEBUG */
+
+#define LDBG(lun, fmt, args...)   dev_dbg (&(lun)->dev, fmt, ## args)
+#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
+#define LWARN(lun, fmt, args...)  dev_warn(&(lun)->dev, fmt, ## args)
+#define LINFO(lun, fmt, args...)  dev_info(&(lun)->dev, fmt, ## args)
+
+
+#ifdef DUMP_MSGS
+
+#  define dump_msg(fsg, /* const char * */ label,                      \
+                  /* const u8 * */ buf, /* unsigned */ length) do {    \
+       if (length < 512) {                                             \
+               DBG(fsg, "%s, length %u:\n", label, length);            \
+               print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,      \
+                              16, 1, buf, length, 0);                  \
+       }                                                               \
+} while (0)
+
+#  define dump_cdb(fsg) do { } while (0)
+
+#else
+
+#  define dump_msg(fsg, /* const char * */ label, \
+                  /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
+
+#  ifdef VERBOSE_DEBUG
+
+#    define dump_cdb(fsg)                                              \
+       print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,      \
+                      16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0)         \
+
+#  else
+
+#    define dump_cdb(fsg) do { } while (0)
+
+#  endif /* VERBOSE_DEBUG */
+
+#endif /* DUMP_MSGS */
+
+/*-------------------------------------------------------------------------*/
+
+/* Length of a SCSI Command Data Block */
+#define MAX_COMMAND_SIZE       16
+
+/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
+#define SS_NO_SENSE                            0
+#define SS_COMMUNICATION_FAILURE               0x040800
+#define SS_INVALID_COMMAND                     0x052000
+#define SS_INVALID_FIELD_IN_CDB                        0x052400
+#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE  0x052100
+#define SS_LOGICAL_UNIT_NOT_SUPPORTED          0x052500
+#define SS_MEDIUM_NOT_PRESENT                  0x023a00
+#define SS_MEDIUM_REMOVAL_PREVENTED            0x055302
+#define SS_NOT_READY_TO_READY_TRANSITION       0x062800
+#define SS_RESET_OCCURRED                      0x062900
+#define SS_SAVING_PARAMETERS_NOT_SUPPORTED     0x053900
+#define SS_UNRECOVERED_READ_ERROR              0x031100
+#define SS_WRITE_ERROR                         0x030c02
+#define SS_WRITE_PROTECTED                     0x072700
+
+#define SK(x)          ((u8) ((x) >> 16))      /* Sense Key byte, etc. */
+#define ASC(x)         ((u8) ((x) >> 8))
+#define ASCQ(x)                ((u8) (x))
+
+
+/*-------------------------------------------------------------------------*/
+
+
+struct fsg_lun {
+       struct file     *filp;
+       loff_t          file_length;
+       loff_t          num_sectors;
+
+       unsigned int    initially_ro:1;
+       unsigned int    ro:1;
+       unsigned int    removable:1;
+       unsigned int    cdrom:1;
+       unsigned int    prevent_medium_removal:1;
+       unsigned int    registered:1;
+       unsigned int    info_valid:1;
+       unsigned int    nofua:1;
+
+       u32             sense_data;
+       u32             sense_data_info;
+       u32             unit_attention_data;
+
+       unsigned int    blkbits;        /* Bits of logical block size of bound block device */
+       unsigned int    blksize;        /* logical block size of bound block device */
+       struct device   dev;
+};
+
+static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
+{
+       return curlun->filp != NULL;
+}
 
 static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
 {
        return container_of(dev, struct fsg_lun, dev);
 }
 
+
+/* Big enough to hold our biggest descriptor */
+#define EP0_BUFSIZE    256
+#define DELAYED_STATUS (EP0_BUFSIZE + 999)     /* An impossibly large value */
+
+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
+
+static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
+module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);
+MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
+
+#else
+
+/*
+ * Number of buffers we will use.
+ * 2 is usually enough for good buffering pipeline
+ */
+#define fsg_num_buffers        CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
+
+#endif /* CONFIG_USB_DEBUG */
+
+/* check if fsg_num_buffers is within a valid range */
+static inline int fsg_num_buffers_validate(void)
+{
+       if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
+               return 0;
+       pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
+              fsg_num_buffers, 2 ,4);
+       return -EINVAL;
+}
+
+/* Default size of buffer length. */
+#define FSG_BUFLEN     ((u32)16384)
+
+/* Maximal number of LUNs supported in mass storage function */
+#define FSG_MAX_LUNS   8
+
+enum fsg_buffer_state {
+       BUF_STATE_EMPTY = 0,
+       BUF_STATE_FULL,
+       BUF_STATE_BUSY
+};
+
+struct fsg_buffhd {
+       void                            *buf;
+       enum fsg_buffer_state           state;
+       struct fsg_buffhd               *next;
+
+       /*
+        * The NetChip 2280 is faster, and handles some protocol faults
+        * better, if we don't submit any short bulk-out read requests.
+        * So we will record the intended request length here.
+        */
+       unsigned int                    bulk_out_intended_length;
+
+       struct usb_request              *inreq;
+       int                             inreq_busy;
+       struct usb_request              *outreq;
+       int                             outreq_busy;
+};
+
+enum fsg_state {
+       /* This one isn't used anywhere */
+       FSG_STATE_COMMAND_PHASE = -10,
+       FSG_STATE_DATA_PHASE,
+       FSG_STATE_STATUS_PHASE,
+
+       FSG_STATE_IDLE = 0,
+       FSG_STATE_ABORT_BULK_OUT,
+       FSG_STATE_RESET,
+       FSG_STATE_INTERFACE_CHANGE,
+       FSG_STATE_CONFIG_CHANGE,
+       FSG_STATE_DISCONNECT,
+       FSG_STATE_EXIT,
+       FSG_STATE_TERMINATED
+};
+
+enum data_direction {
+       DATA_DIR_UNKNOWN = 0,
+       DATA_DIR_FROM_HOST,
+       DATA_DIR_TO_HOST,
+       DATA_DIR_NONE
+};
+
+
+/*-------------------------------------------------------------------------*/
+
+
+static inline u32 get_unaligned_be24(u8 *buf)
+{
+       return 0xffffff & (u32) get_unaligned_be32(buf - 1);
+}
+
+
+/*-------------------------------------------------------------------------*/
+
+
+enum {
+       FSG_STRING_INTERFACE
+};
+
+
 /* There is only one interface. */
 
-struct usb_interface_descriptor fsg_intf_desc = {
+static struct usb_interface_descriptor
+fsg_intf_desc = {
        .bLength =              sizeof fsg_intf_desc,
        .bDescriptorType =      USB_DT_INTERFACE,
 
@@ -48,14 +268,14 @@ struct usb_interface_descriptor fsg_intf_desc = {
        .bInterfaceProtocol =   USB_PR_BULK,    /* Adjusted during fsg_bind() */
        .iInterface =           FSG_STRING_INTERFACE,
 };
-EXPORT_SYMBOL(fsg_intf_desc);
 
 /*
  * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
  * interrupt-in.
  */
 
-struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = {
+static struct usb_endpoint_descriptor
+fsg_fs_bulk_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -63,9 +283,9 @@ struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
        /* wMaxPacketSize set by autoconfiguration */
 };
-EXPORT_SYMBOL(fsg_fs_bulk_in_desc);
 
-struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
+static struct usb_endpoint_descriptor
+fsg_fs_bulk_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -73,15 +293,13 @@ struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
        /* wMaxPacketSize set by autoconfiguration */
 };
-EXPORT_SYMBOL(fsg_fs_bulk_out_desc);
 
-struct usb_descriptor_header *fsg_fs_function[] = {
+static struct usb_descriptor_header *fsg_fs_function[] = {
        (struct usb_descriptor_header *) &fsg_intf_desc,
        (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
        (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
        NULL,
 };
-EXPORT_SYMBOL(fsg_fs_function);
 
 
 /*
@@ -92,7 +310,8 @@ EXPORT_SYMBOL(fsg_fs_function);
  * and a "device qualifier" ... plus more construction options
  * for the configuration descriptor.
  */
-struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = {
+static struct usb_endpoint_descriptor
+fsg_hs_bulk_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -100,9 +319,9 @@ struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
        .wMaxPacketSize =       cpu_to_le16(512),
 };
-EXPORT_SYMBOL(fsg_hs_bulk_in_desc);
 
-struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
+static struct usb_endpoint_descriptor
+fsg_hs_bulk_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -111,18 +330,17 @@ struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
        .wMaxPacketSize =       cpu_to_le16(512),
        .bInterval =            1,      /* NAK every 1 uframe */
 };
-EXPORT_SYMBOL(fsg_hs_bulk_out_desc);
 
 
-struct usb_descriptor_header *fsg_hs_function[] = {
+static struct usb_descriptor_header *fsg_hs_function[] = {
        (struct usb_descriptor_header *) &fsg_intf_desc,
        (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
        (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
        NULL,
 };
-EXPORT_SYMBOL(fsg_hs_function);
 
-struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
+static struct usb_endpoint_descriptor
+fsg_ss_bulk_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -130,17 +348,16 @@ struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
        .wMaxPacketSize =       cpu_to_le16(1024),
 };
-EXPORT_SYMBOL(fsg_ss_bulk_in_desc);
 
-struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = {
+static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = {
        .bLength =              sizeof(fsg_ss_bulk_in_comp_desc),
        .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
 
        /*.bMaxBurst =          DYNAMIC, */
 };
-EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc);
 
-struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = {
+static struct usb_endpoint_descriptor
+fsg_ss_bulk_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -148,17 +365,15 @@ struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
        .wMaxPacketSize =       cpu_to_le16(1024),
 };
-EXPORT_SYMBOL(fsg_ss_bulk_out_desc);
 
-struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
+static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
        .bLength =              sizeof(fsg_ss_bulk_in_comp_desc),
        .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
 
        /*.bMaxBurst =          DYNAMIC, */
 };
-EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc);
 
-struct usb_descriptor_header *fsg_ss_function[] = {
+static struct usb_descriptor_header *fsg_ss_function[] = {
        (struct usb_descriptor_header *) &fsg_intf_desc,
        (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
        (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
@@ -166,7 +381,17 @@ struct usb_descriptor_header *fsg_ss_function[] = {
        (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
        NULL,
 };
-EXPORT_SYMBOL(fsg_ss_function);
+
+/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
+static struct usb_string               fsg_strings[] = {
+       {FSG_STRING_INTERFACE,          fsg_string_interface},
+       {}
+};
+
+static struct usb_gadget_strings       fsg_stringtab = {
+       .language       = 0x0409,               /* en-us */
+       .strings        = fsg_strings,
+};
 
 
  /*-------------------------------------------------------------------------*/
@@ -176,7 +401,7 @@ EXPORT_SYMBOL(fsg_ss_function);
  * the caller must own fsg->filesem for writing.
  */
 
-void fsg_lun_close(struct fsg_lun *curlun)
+static void fsg_lun_close(struct fsg_lun *curlun)
 {
        if (curlun->filp) {
                LDBG(curlun, "close backing file\n");
@@ -184,9 +409,9 @@ void fsg_lun_close(struct fsg_lun *curlun)
                curlun->filp = NULL;
        }
 }
-EXPORT_SYMBOL(fsg_lun_close);
 
-int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
+
+static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
 {
        int                             ro;
        struct file                     *filp = NULL;
@@ -283,7 +508,6 @@ out:
        fput(filp);
        return rc;
 }
-EXPORT_SYMBOL(fsg_lun_open);
 
 
 /*-------------------------------------------------------------------------*/
@@ -292,7 +516,7 @@ EXPORT_SYMBOL(fsg_lun_open);
  * Sync the file data, don't bother with the metadata.
  * This code was copied from fs/buffer.c:sys_fdatasync().
  */
-int fsg_lun_fsync_sub(struct fsg_lun *curlun)
+static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
 {
        struct file     *filp = curlun->filp;
 
@@ -300,9 +524,8 @@ int fsg_lun_fsync_sub(struct fsg_lun *curlun)
                return 0;
        return vfs_fsync(filp, 1);
 }
-EXPORT_SYMBOL(fsg_lun_fsync_sub);
 
-void store_cdrom_address(u8 *dest, int msf, u32 addr)
+static void store_cdrom_address(u8 *dest, int msf, u32 addr)
 {
        if (msf) {
                /* Convert to Minutes-Seconds-Frames */
@@ -319,12 +542,12 @@ void store_cdrom_address(u8 *dest, int msf, u32 addr)
                put_unaligned_be32(addr, dest);
        }
 }
-EXPORT_SYMBOL(store_cdrom_address);
+
 
 /*-------------------------------------------------------------------------*/
 
 
-ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
+static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
                           char *buf)
 {
        struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
@@ -333,18 +556,16 @@ ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
                                  ? curlun->ro
                                  : curlun->initially_ro);
 }
-EXPORT_SYMBOL(fsg_show_ro);
 
-ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
+static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
                              char *buf)
 {
        struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
 
        return sprintf(buf, "%u\n", curlun->nofua);
 }
-EXPORT_SYMBOL(fsg_show_nofua);
 
-ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
+static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
                             char *buf)
 {
        struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
@@ -370,10 +591,9 @@ ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
        up_read(filesem);
        return rc;
 }
-EXPORT_SYMBOL(fsg_show_file);
 
 
-ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
+static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
                            const char *buf, size_t count)
 {
        ssize_t         rc;
@@ -402,9 +622,8 @@ ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
        up_read(filesem);
        return rc;
 }
-EXPORT_SYMBOL(fsg_store_ro);
 
-ssize_t fsg_store_nofua(struct device *dev,
+static ssize_t fsg_store_nofua(struct device *dev,
                               struct device_attribute *attr,
                               const char *buf, size_t count)
 {
@@ -424,9 +643,8 @@ ssize_t fsg_store_nofua(struct device *dev,
 
        return count;
 }
-EXPORT_SYMBOL(fsg_store_nofua);
 
-ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
+static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
                              const char *buf, size_t count)
 {
        struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
@@ -457,6 +675,3 @@ ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
        up_write(filesem);
        return (rc < 0 ? rc : count);
 }
-EXPORT_SYMBOL(fsg_store_file);
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/storage_common.h b/drivers/usb/gadget/storage_common.h
deleted file mode 100644 (file)
index 1fcda2b..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-#ifndef USB_STORAGE_COMMON_H
-#define USB_STORAGE_COMMON_H
-
-#include <linux/device.h>
-#include <linux/usb/storage.h>
-#include <scsi/scsi.h>
-#include <asm/unaligned.h>
-
-#ifndef DEBUG
-#undef VERBOSE_DEBUG
-#undef DUMP_MSGS
-#endif /* !DEBUG */
-
-#ifdef VERBOSE_DEBUG
-#define VLDBG  LDBG
-#else
-#define VLDBG(lun, fmt, args...) do { } while (0)
-#endif /* VERBOSE_DEBUG */
-
-#define LDBG(lun, fmt, args...)   dev_dbg(&(lun)->dev, fmt, ## args)
-#define LERROR(lun, fmt, args...) dev_err(&(lun)->dev, fmt, ## args)
-#define LWARN(lun, fmt, args...)  dev_warn(&(lun)->dev, fmt, ## args)
-#define LINFO(lun, fmt, args...)  dev_info(&(lun)->dev, fmt, ## args)
-
-#ifdef DUMP_MSGS
-
-#  define dump_msg(fsg, /* const char * */ label,                      \
-                  /* const u8 * */ buf, /* unsigned */ length)         \
-do {                                                                   \
-       if (length < 512) {                                             \
-               DBG(fsg, "%s, length %u:\n", label, length);            \
-               print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,      \
-                              16, 1, buf, length, 0);                  \
-       }                                                               \
-} while (0)
-
-#  define dump_cdb(fsg) do { } while (0)
-
-#else
-
-#  define dump_msg(fsg, /* const char * */ label, \
-                  /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
-
-#  ifdef VERBOSE_DEBUG
-
-#    define dump_cdb(fsg)                                              \
-       print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,      \
-                      16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0)         \
-
-#  else
-
-#    define dump_cdb(fsg) do { } while (0)
-
-#  endif /* VERBOSE_DEBUG */
-
-#endif /* DUMP_MSGS */
-
-/* Length of a SCSI Command Data Block */
-#define MAX_COMMAND_SIZE       16
-
-/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
-#define SS_NO_SENSE                            0
-#define SS_COMMUNICATION_FAILURE               0x040800
-#define SS_INVALID_COMMAND                     0x052000
-#define SS_INVALID_FIELD_IN_CDB                        0x052400
-#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE  0x052100
-#define SS_LOGICAL_UNIT_NOT_SUPPORTED          0x052500
-#define SS_MEDIUM_NOT_PRESENT                  0x023a00
-#define SS_MEDIUM_REMOVAL_PREVENTED            0x055302
-#define SS_NOT_READY_TO_READY_TRANSITION       0x062800
-#define SS_RESET_OCCURRED                      0x062900
-#define SS_SAVING_PARAMETERS_NOT_SUPPORTED     0x053900
-#define SS_UNRECOVERED_READ_ERROR              0x031100
-#define SS_WRITE_ERROR                         0x030c02
-#define SS_WRITE_PROTECTED                     0x072700
-
-#define SK(x)          ((u8) ((x) >> 16))      /* Sense Key byte, etc. */
-#define ASC(x)         ((u8) ((x) >> 8))
-#define ASCQ(x)                ((u8) (x))
-
-struct fsg_lun {
-       struct file     *filp;
-       loff_t          file_length;
-       loff_t          num_sectors;
-
-       unsigned int    initially_ro:1;
-       unsigned int    ro:1;
-       unsigned int    removable:1;
-       unsigned int    cdrom:1;
-       unsigned int    prevent_medium_removal:1;
-       unsigned int    registered:1;
-       unsigned int    info_valid:1;
-       unsigned int    nofua:1;
-
-       u32             sense_data;
-       u32             sense_data_info;
-       u32             unit_attention_data;
-
-       unsigned int    blkbits; /* Bits of logical block size
-                                                      of bound block device */
-       unsigned int    blksize; /* logical block size of bound block device */
-       struct device   dev;
-};
-
-static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
-{
-       return curlun->filp != NULL;
-}
-
-/* Big enough to hold our biggest descriptor */
-#define EP0_BUFSIZE    256
-#define DELAYED_STATUS (EP0_BUFSIZE + 999)     /* An impossibly large value */
-
-/* Default size of buffer length. */
-#define FSG_BUFLEN     ((u32)16384)
-
-/* Maximal number of LUNs supported in mass storage function */
-#define FSG_MAX_LUNS   8
-
-enum fsg_buffer_state {
-       BUF_STATE_EMPTY = 0,
-       BUF_STATE_FULL,
-       BUF_STATE_BUSY
-};
-
-struct fsg_buffhd {
-       void                            *buf;
-       enum fsg_buffer_state           state;
-       struct fsg_buffhd               *next;
-
-       /*
-        * The NetChip 2280 is faster, and handles some protocol faults
-        * better, if we don't submit any short bulk-out read requests.
-        * So we will record the intended request length here.
-        */
-       unsigned int                    bulk_out_intended_length;
-
-       struct usb_request              *inreq;
-       int                             inreq_busy;
-       struct usb_request              *outreq;
-       int                             outreq_busy;
-};
-
-enum fsg_state {
-       /* This one isn't used anywhere */
-       FSG_STATE_COMMAND_PHASE = -10,
-       FSG_STATE_DATA_PHASE,
-       FSG_STATE_STATUS_PHASE,
-
-       FSG_STATE_IDLE = 0,
-       FSG_STATE_ABORT_BULK_OUT,
-       FSG_STATE_RESET,
-       FSG_STATE_INTERFACE_CHANGE,
-       FSG_STATE_CONFIG_CHANGE,
-       FSG_STATE_DISCONNECT,
-       FSG_STATE_EXIT,
-       FSG_STATE_TERMINATED
-};
-
-enum data_direction {
-       DATA_DIR_UNKNOWN = 0,
-       DATA_DIR_FROM_HOST,
-       DATA_DIR_TO_HOST,
-       DATA_DIR_NONE
-};
-
-static inline u32 get_unaligned_be24(u8 *buf)
-{
-       return 0xffffff & (u32) get_unaligned_be32(buf - 1);
-}
-
-enum {
-       FSG_STRING_INTERFACE
-};
-
-extern struct usb_interface_descriptor fsg_intf_desc;
-
-extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc;
-extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_fs_function[];
-
-extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc;
-extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_hs_function[];
-
-extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc;
-extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc;
-extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc;
-extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc;
-extern struct usb_descriptor_header *fsg_ss_function[];
-
-void fsg_lun_close(struct fsg_lun *curlun);
-int fsg_lun_open(struct fsg_lun *curlun, const char *filename);
-int fsg_lun_fsync_sub(struct fsg_lun *curlun);
-void store_cdrom_address(u8 *dest, int msf, u32 addr);
-ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
-                   char *buf);
-ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
-                      char *buf);
-ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
-                     char *buf);
-ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
-                    const char *buf, size_t count);
-ssize_t fsg_store_nofua(struct device *dev,
-                       struct device_attribute *attr,
-                       const char *buf, size_t count);
-ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
-                      const char *buf, size_t count);
-
-#endif /* USB_STORAGE_COMMON_H */