]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/usb/gadget/function/f_mass_storage.c
MLK-11483-1 make the kernel image for mfgtool
[karo-tx-linux.git] / drivers / usb / gadget / function / f_mass_storage.c
index 5ec533826621c7cfcb0975f9084f0ec4df3b7cf1..ffd38fc6b2e389e09cabf7ec95496d9e0336e756 100644 (file)
@@ -335,8 +335,15 @@ struct fsg_dev {
 
        struct usb_ep           *bulk_in;
        struct usb_ep           *bulk_out;
+#ifdef CONFIG_FSL_UTP
+       void                    *utp;
+#endif
 };
 
+#ifdef CONFIG_FSL_UTP
+#include "fsl_updater.h"
+#endif
+
 static inline int __fsg_is_set(struct fsg_common *common,
                               const char *func, unsigned line)
 {
@@ -1140,6 +1147,13 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
        }
 #endif
 
+#ifdef CONFIG_FSL_UTP
+       if (utp_get_sense(common->fsg) == 0) {  /* got the sense from the UTP */
+               sd = UTP_CTX(common->fsg)->sd;
+               sdinfo = UTP_CTX(common->fsg)->sdinfo;
+               valid = 0;
+       } else
+#endif
        if (!curlun) {          /* Unsupported LUNs are okay */
                common->bad_lun_okay = 1;
                sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
@@ -1161,6 +1175,9 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
        buf[7] = 18 - 8;                        /* Additional sense length */
        buf[12] = ASC(sd);
        buf[13] = ASCQ(sd);
+#ifdef CONFIG_FSL_UTP
+       put_unaligned_be32(UTP_CTX(common->fsg)->sdinfo_h, &buf[8]);
+#endif
        return 18;
 }
 
@@ -1654,7 +1671,18 @@ static int send_status(struct fsg_common *common)
                sd = SS_INVALID_COMMAND;
        } else if (sd != SS_NO_SENSE) {
                DBG(common, "sending command-failure status\n");
+#ifdef CONFIG_FSL_UTP
+/*
+ * mfgtool host frequently reset bus during transfer
+ *  - the response in csw to request sense will be 1 due to UTP change
+ *    some storage information
+ *  - host will reset the bus if response to request sense is 1
+ *  - change the response to 0 if CONFIG_FSL_UTP is defined
+ */
+               status = US_BULK_STAT_OK;
+#else
                status = US_BULK_STAT_FAIL;
+#endif
                VDBG(common, "  sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
                                "  info x%x\n",
                                SK(sd), ASC(sd), ASCQ(sd), sdinfo);
@@ -1845,6 +1873,13 @@ static int do_scsi_command(struct fsg_common *common)
        common->phase_error = 0;
        common->short_packet_received = 0;
 
+#ifdef CONFIG_FSL_UTP
+       reply = utp_handle_message(common->fsg, common->cmnd, reply);
+
+       if (reply != -EINVAL)
+               return reply;
+#endif
+
        down_read(&common->filesem);    /* We're using the backing file */
        switch (common->cmnd[0]) {
 
@@ -2508,12 +2543,14 @@ static int fsg_main_thread(void *common_)
        /* Allow the thread to be frozen */
        set_freezable();
 
+#ifndef CONFIG_FSL_UTP
        /*
         * Arrange for userspace references to be interpreted as kernel
         * pointers.  That way we can pass a kernel pointer to a routine
         * that expects a __user pointer and it will work okay.
         */
        set_fs(get_ds());
+#endif
 
        /* The main loop */
        while (common->state != FSG_STATE_TERMINATED) {
@@ -3025,6 +3062,10 @@ static void fsg_common_release(struct kref *ref)
 
 /*-------------------------------------------------------------------------*/
 
+#ifdef CONFIG_FSL_UTP
+#include "fsl_updater.c"
+#endif
+
 static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
 {
        struct fsg_dev          *fsg = fsg_from_func(f);
@@ -3064,6 +3105,10 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
        fsg_intf_desc.bInterfaceNumber = i;
        fsg->interface_number = i;
 
+#ifdef CONFIG_FSL_UTP
+       utp_init(fsg);
+#endif
+
        /* Find all the endpoints we will use */
        ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
        if (!ep)
@@ -3127,6 +3172,11 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
        }
 
        usb_free_all_descriptors(&fsg->function);
+
+#ifdef CONFIG_FSL_UTP
+       utp_exit(fsg);
+#endif
+
 }
 
 static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
@@ -3140,9 +3190,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
                            func_inst.group);
 }
 
-CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
-CONFIGFS_ATTR_OPS(fsg_lun_opts);
-
 static void fsg_lun_attr_release(struct config_item *item)
 {
        struct fsg_lun_opts *lun_opts;
@@ -3153,110 +3200,93 @@ static void fsg_lun_attr_release(struct config_item *item)
 
 static struct configfs_item_operations fsg_lun_item_ops = {
        .release                = fsg_lun_attr_release,
-       .show_attribute         = fsg_lun_opts_attr_show,
-       .store_attribute        = fsg_lun_opts_attr_store,
 };
 
-static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page)
+static ssize_t fsg_lun_opts_file_show(struct config_item *item, char *page)
 {
-       struct fsg_opts *fsg_opts;
-
-       fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+       struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
+       struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
 
        return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
 }
 
-static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_file_store(struct config_item *item,
                                       const char *page, size_t len)
 {
-       struct fsg_opts *fsg_opts;
-
-       fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+       struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
+       struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
 
        return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len);
 }
 
-static struct fsg_lun_opts_attribute fsg_lun_opts_file =
-       __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show,
-                       fsg_lun_opts_file_store);
+CONFIGFS_ATTR(fsg_lun_opts_, file);
 
-static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page)
+static ssize_t fsg_lun_opts_ro_show(struct config_item *item, char *page)
 {
-       return fsg_show_ro(opts->lun, page);
+       return fsg_show_ro(to_fsg_lun_opts(item)->lun, page);
 }
 
-static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_ro_store(struct config_item *item,
                                       const char *page, size_t len)
 {
-       struct fsg_opts *fsg_opts;
-
-       fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+       struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
+       struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
 
        return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len);
 }
 
-static struct fsg_lun_opts_attribute fsg_lun_opts_ro =
-       __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show,
-                       fsg_lun_opts_ro_store);
+CONFIGFS_ATTR(fsg_lun_opts_, ro);
 
-static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_removable_show(struct config_item *item,
                                           char *page)
 {
-       return fsg_show_removable(opts->lun, page);
+       return fsg_show_removable(to_fsg_lun_opts(item)->lun, page);
 }
 
-static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_removable_store(struct config_item *item,
                                       const char *page, size_t len)
 {
-       return fsg_store_removable(opts->lun, page, len);
+       return fsg_store_removable(to_fsg_lun_opts(item)->lun, page, len);
 }
 
-static struct fsg_lun_opts_attribute fsg_lun_opts_removable =
-       __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR,
-                       fsg_lun_opts_removable_show,
-                       fsg_lun_opts_removable_store);
+CONFIGFS_ATTR(fsg_lun_opts_, removable);
 
-static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page)
+static ssize_t fsg_lun_opts_cdrom_show(struct config_item *item, char *page)
 {
-       return fsg_show_cdrom(opts->lun, page);
+       return fsg_show_cdrom(to_fsg_lun_opts(item)->lun, page);
 }
 
-static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_cdrom_store(struct config_item *item,
                                       const char *page, size_t len)
 {
-       struct fsg_opts *fsg_opts;
-
-       fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+       struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
+       struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
 
        return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
                               len);
 }
 
-static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom =
-       __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show,
-                       fsg_lun_opts_cdrom_store);
+CONFIGFS_ATTR(fsg_lun_opts_, cdrom);
 
-static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page)
+static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page)
 {
-       return fsg_show_nofua(opts->lun, page);
+       return fsg_show_nofua(to_fsg_lun_opts(item)->lun, page);
 }
 
-static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts,
+static ssize_t fsg_lun_opts_nofua_store(struct config_item *item,
                                       const char *page, size_t len)
 {
-       return fsg_store_nofua(opts->lun, page, len);
+       return fsg_store_nofua(to_fsg_lun_opts(item)->lun, page, len);
 }
 
-static struct fsg_lun_opts_attribute fsg_lun_opts_nofua =
-       __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show,
-                       fsg_lun_opts_nofua_store);
+CONFIGFS_ATTR(fsg_lun_opts_, nofua);
 
 static struct configfs_attribute *fsg_lun_attrs[] = {
-       &fsg_lun_opts_file.attr,
-       &fsg_lun_opts_ro.attr,
-       &fsg_lun_opts_removable.attr,
-       &fsg_lun_opts_cdrom.attr,
-       &fsg_lun_opts_nofua.attr,
+       &fsg_lun_opts_attr_file,
+       &fsg_lun_opts_attr_ro,
+       &fsg_lun_opts_attr_removable,
+       &fsg_lun_opts_attr_cdrom,
+       &fsg_lun_opts_attr_nofua,
        NULL,
 };
 
@@ -3348,9 +3378,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item)
        config_item_put(item);
 }
 
-CONFIGFS_ATTR_STRUCT(fsg_opts);
-CONFIGFS_ATTR_OPS(fsg_opts);
-
 static void fsg_attr_release(struct config_item *item)
 {
        struct fsg_opts *opts = to_fsg_opts(item);
@@ -3360,12 +3387,11 @@ static void fsg_attr_release(struct config_item *item)
 
 static struct configfs_item_operations fsg_item_ops = {
        .release                = fsg_attr_release,
-       .show_attribute         = fsg_opts_attr_show,
-       .store_attribute        = fsg_opts_attr_store,
 };
 
-static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
+static ssize_t fsg_opts_stall_show(struct config_item *item, char *page)
 {
+       struct fsg_opts *opts = to_fsg_opts(item);
        int result;
 
        mutex_lock(&opts->lock);
@@ -3375,9 +3401,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
        return result;
 }
 
-static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
+static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page,
                                    size_t len)
 {
+       struct fsg_opts *opts = to_fsg_opts(item);
        int ret;
        bool stall;
 
@@ -3399,13 +3426,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
        return ret;
 }
 
-static struct fsg_opts_attribute fsg_opts_stall =
-       __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show,
-                       fsg_opts_stall_store);
+CONFIGFS_ATTR(fsg_opts_, stall);
 
 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
-static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
+static ssize_t fsg_opts_num_buffers_show(struct config_item *item, char *page)
 {
+       struct fsg_opts *opts = to_fsg_opts(item);
        int result;
 
        mutex_lock(&opts->lock);
@@ -3415,9 +3441,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
        return result;
 }
 
-static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts,
+static ssize_t fsg_opts_num_buffers_store(struct config_item *item,
                                          const char *page, size_t len)
 {
+       struct fsg_opts *opts = to_fsg_opts(item);
        int ret;
        u8 num;
 
@@ -3442,17 +3469,13 @@ end:
        return ret;
 }
 
-static struct fsg_opts_attribute fsg_opts_num_buffers =
-       __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR,
-                       fsg_opts_num_buffers_show,
-                       fsg_opts_num_buffers_store);
-
+CONFIGFS_ATTR(fsg_opts_, num_buffers);
 #endif
 
 static struct configfs_attribute *fsg_attrs[] = {
-       &fsg_opts_stall.attr,
+       &fsg_opts_attr_stall,
 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
-       &fsg_opts_num_buffers.attr,
+       &fsg_opts_attr_num_buffers,
 #endif
        NULL,
 };