Commit 2412fbf1 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: mass_storage: convert to new interface of f_mass_storage

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: default avatarAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent e5eaa0dc
...@@ -885,6 +885,7 @@ config USB_MASS_STORAGE ...@@ -885,6 +885,7 @@ config USB_MASS_STORAGE
depends on BLOCK depends on BLOCK
select USB_LIBCOMPOSITE select USB_LIBCOMPOSITE
select USB_U_MS select USB_U_MS
select USB_F_MASS_STORAGE
help help
The Mass Storage Gadget acts as a USB Mass Storage disk drive. 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 As its storage repository it can use a regular file or a block
......
...@@ -2827,6 +2827,13 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns) ...@@ -2827,6 +2827,13 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
} }
EXPORT_SYMBOL_GPL_IF_MODULE(fsg_common_set_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) void fsg_common_free_buffers(struct fsg_common *common)
{ {
_fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
......
...@@ -132,6 +132,9 @@ void fsg_common_free_luns(struct fsg_common *common); ...@@ -132,6 +132,9 @@ void fsg_common_free_luns(struct fsg_common *common);
int fsg_common_set_nluns(struct fsg_common *common, int nluns); 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, int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
unsigned int id, const char *name, unsigned int id, const char *name,
const char **name_pfx); const char **name_pfx);
......
...@@ -46,17 +46,7 @@ ...@@ -46,17 +46,7 @@
#define FSG_VENDOR_ID 0x0525 /* NetChip */ #define FSG_VENDOR_ID 0x0525 /* NetChip */
#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
/*-------------------------------------------------------------------------*/ #include "f_mass_storage.h"
/*
* 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"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
USB_GADGET_COMPOSITE_OPTIONS(); USB_GADGET_COMPOSITE_OPTIONS();
...@@ -107,6 +97,9 @@ static struct usb_gadget_strings *dev_strings[] = { ...@@ -107,6 +97,9 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL, NULL,
}; };
static struct usb_function_instance *fi_msg;
static struct usb_function *f_msg;
/****************************** Configurations ******************************/ /****************************** Configurations ******************************/
static struct fsg_module_parameters mod_data = { static struct fsg_module_parameters mod_data = {
...@@ -139,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common) ...@@ -139,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
static int __init msg_do_config(struct usb_configuration *c) static int __init msg_do_config(struct usb_configuration *c)
{ {
static const struct fsg_operations ops = { struct fsg_opts *opts;
.thread_exits = msg_thread_exits,
};
static struct fsg_common common;
struct fsg_common *retp;
struct fsg_config config;
int ret; int ret;
if (gadget_is_otg(c->cdev->gadget)) { if (gadget_is_otg(c->cdev->gadget)) {
...@@ -153,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration *c) ...@@ -153,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
fsg_config_from_params(&config, &mod_data, fsg_num_buffers); opts = fsg_opts_from_func_inst(fi_msg);
config.ops = &ops;
f_msg = usb_get_function(fi_msg);
if (IS_ERR(f_msg))
return PTR_ERR(f_msg);
ret = fsg_common_run_thread(opts->common);
if (ret)
goto put_func;
retp = fsg_common_init(&common, c->cdev, &config); ret = usb_add_function(c, f_msg);
if (IS_ERR(retp)) if (ret)
return PTR_ERR(retp); goto put_func;
return 0;
ret = fsg_bind_config(c->cdev, c, &common); put_func:
fsg_common_put(&common); usb_put_function(f_msg);
return ret; return ret;
} }
...@@ -176,23 +172,79 @@ static struct usb_configuration msg_config_driver = { ...@@ -176,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
static int __init msg_bind(struct usb_composite_dev *cdev) 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; 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); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
return status; goto fail_string_ids;
msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
status = usb_add_config(cdev, &msg_config_driver, msg_do_config); status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
if (status < 0) if (status < 0)
return status; goto fail_string_ids;
usb_composite_overwrite_options(cdev, &coverwrite); usb_composite_overwrite_options(cdev, &coverwrite);
dev_info(&cdev->gadget->dev, dev_info(&cdev->gadget->dev,
DRIVER_DESC ", version: " DRIVER_VERSION "\n"); DRIVER_DESC ", version: " DRIVER_VERSION "\n");
set_bit(0, &msg_registered); set_bit(0, &msg_registered);
return 0; 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 ******************************/ /****************************** Some noise ******************************/
...@@ -203,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = { ...@@ -203,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = {
.needs_serial = 1, .needs_serial = 1,
.strings = dev_strings, .strings = dev_strings,
.bind = msg_bind, .bind = msg_bind,
.unbind = msg_unbind,
}; };
MODULE_DESCRIPTION(DRIVER_DESC); MODULE_DESCRIPTION(DRIVER_DESC);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment