usb: gadget: mass_storage: convert to new interface of f_mass_storage
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Wed, 9 Oct 2013 08:06:02 +0000 (10:06 +0200)
committerFelipe Balbi <balbi@ti.com>
Thu, 10 Oct 2013 15:24:10 +0000 (10:24 -0500)
Convert old mass_storage gadget to use the new interface of f_mass_storage
so that later the compatibility layer in f_mass_storage can be removed.

struct fsg_common is not known to mass_storage.c, so a setter method
is added to f_mass_storage.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/Kconfig
drivers/usb/gadget/f_mass_storage.c
drivers/usb/gadget/f_mass_storage.h
drivers/usb/gadget/mass_storage.c

index 40adaf08d3a5bbc99a1e7504622a56ed6ecfc565..7d64e474c48bc49e8f1b9f5663bcea73aafbad7a 100644 (file)
@@ -885,6 +885,7 @@ config USB_MASS_STORAGE
        depends on BLOCK
        select USB_LIBCOMPOSITE
        select USB_U_MS
+       select USB_F_MASS_STORAGE
        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
index a063cd5e5533c53533f3f96fb0f38b822aa262ab..d6c2da0fb759e2026208fa9226012f421d00efa3 100644 (file)
@@ -2827,6 +2827,13 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
 }
 EXPORT_SYMBOL_GPL_IF_MODULE(fsg_common_set_nluns);
 
+void fsg_common_set_ops(struct fsg_common *common,
+                       const struct fsg_operations *ops)
+{
+       common->ops = ops;
+}
+EXPORT_SYMBOL_GPL_IF_MODULE(fsg_common_set_ops);
+
 void fsg_common_free_buffers(struct fsg_common *common)
 {
        _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
index 42f7db4084781adaa69d94836eb712e35d5b74ec..b53cf8c9189e46c0b9c23ead1d664148435907e2 100644 (file)
@@ -132,6 +132,9 @@ void fsg_common_free_luns(struct fsg_common *common);
 
 int fsg_common_set_nluns(struct fsg_common *common, int nluns);
 
+void fsg_common_set_ops(struct fsg_common *common,
+                       const struct fsg_operations *ops);
+
 int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
                          unsigned int id, const char *name,
                          const char **name_pfx);
index f6702514f5d79517a0896d8d7ec23006bc3d6204..8e27a8c9644470bfa8d5b44fc95a198aeda7214f 100644 (file)
 #define FSG_VENDOR_ID  0x0525  /* NetChip */
 #define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
 
-/*-------------------------------------------------------------------------*/
-
-/*
- * kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
- */
-#define USB_FMS_INCLUDED
-#include "f_mass_storage.c"
+#include "f_mass_storage.h"
 
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
@@ -107,6 +97,9 @@ static struct usb_gadget_strings *dev_strings[] = {
        NULL,
 };
 
+static struct usb_function_instance *fi_msg;
+static struct usb_function *f_msg;
+
 /****************************** Configurations ******************************/
 
 static struct fsg_module_parameters mod_data = {
@@ -139,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
 
 static int __init msg_do_config(struct usb_configuration *c)
 {
-       static const struct fsg_operations ops = {
-               .thread_exits = msg_thread_exits,
-       };
-       static struct fsg_common common;
-
-       struct fsg_common *retp;
-       struct fsg_config config;
+       struct fsg_opts *opts;
        int ret;
 
        if (gadget_is_otg(c->cdev->gadget)) {
@@ -153,15 +140,24 @@ 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);
-       config.ops = &ops;
+       opts = fsg_opts_from_func_inst(fi_msg);
+
+       f_msg = usb_get_function(fi_msg);
+       if (IS_ERR(f_msg))
+               return PTR_ERR(f_msg);
 
-       retp = fsg_common_init(&common, c->cdev, &config);
-       if (IS_ERR(retp))
-               return PTR_ERR(retp);
+       ret = fsg_common_run_thread(opts->common);
+       if (ret)
+               goto put_func;
 
-       ret = fsg_bind_config(c->cdev, c, &common);
-       fsg_common_put(&common);
+       ret = usb_add_function(c, f_msg);
+       if (ret)
+               goto put_func;
+
+       return 0;
+
+put_func:
+       usb_put_function(f_msg);
        return ret;
 }
 
@@ -176,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
 
 static int __init msg_bind(struct usb_composite_dev *cdev)
 {
+       static const struct fsg_operations ops = {
+               .thread_exits = msg_thread_exits,
+       };
+       struct fsg_opts *opts;
+       struct fsg_config config;
        int status;
 
+       fi_msg = usb_get_function_instance("mass_storage");
+       if (IS_ERR(fi_msg))
+               return PTR_ERR(fi_msg);
+
+       fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
+       opts = fsg_opts_from_func_inst(fi_msg);
+
+       opts->no_configfs = true;
+       status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
+       if (status)
+               goto fail;
+
+       status = fsg_common_set_nluns(opts->common, config.nluns);
+       if (status)
+               goto fail_set_nluns;
+
+       fsg_common_set_ops(opts->common, &ops);
+
+       status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
+       if (status)
+               goto fail_set_cdev;
+
+       fsg_common_set_sysfs(opts->common, true);
+       status = fsg_common_create_luns(opts->common, &config);
+       if (status)
+               goto fail_set_cdev;
+
+       fsg_common_set_inquiry_string(opts->common, config.vendor_name,
+                                     config.product_name);
+
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
-               return status;
+               goto fail_string_ids;
        msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
        status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
        if (status < 0)
-               return status;
+               goto fail_string_ids;
+
        usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&cdev->gadget->dev,
                 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
        set_bit(0, &msg_registered);
        return 0;
+
+fail_string_ids:
+       fsg_common_remove_luns(opts->common);
+fail_set_cdev:
+       fsg_common_free_luns(opts->common);
+fail_set_nluns:
+       fsg_common_free_buffers(opts->common);
+fail:
+       usb_put_function_instance(fi_msg);
+       return status;
 }
 
+static int msg_unbind(struct usb_composite_dev *cdev)
+{
+       if (!IS_ERR(f_msg))
+               usb_put_function(f_msg);
+
+       if (!IS_ERR(fi_msg))
+               usb_put_function_instance(fi_msg);
+
+       return 0;
+}
 
 /****************************** Some noise ******************************/
 
@@ -203,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = {
        .needs_serial   = 1,
        .strings        = dev_strings,
        .bind           = msg_bind,
+       .unbind         = msg_unbind,
 };
 
 MODULE_DESCRIPTION(DRIVER_DESC);