Commit f3fed367 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: f_mass_storage: factor out a header file

In order to prepare for the new function interface the f_mass_storage.c
needs to be compiled as a module, and so a header file will be required.

This patch factors out some code to a new f_mass_storage.h.
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 6fdc5dd2
...@@ -229,6 +229,7 @@ ...@@ -229,6 +229,7 @@
static const char fsg_string_interface[] = "Mass Storage"; static const char fsg_string_interface[] = "Mass Storage";
#include "storage_common.h" #include "storage_common.h"
#include "f_mass_storage.h"
/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
static struct usb_string fsg_strings[] = { static struct usb_string fsg_strings[] = {
...@@ -246,18 +247,6 @@ static struct usb_gadget_strings fsg_stringtab = { ...@@ -246,18 +247,6 @@ static struct usb_gadget_strings fsg_stringtab = {
struct fsg_dev; struct fsg_dev;
struct fsg_common; 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);
};
/* Data shared by all the FSG instances. */ /* Data shared by all the FSG instances. */
struct fsg_common { struct fsg_common {
struct usb_gadget *gadget; struct usb_gadget *gadget;
...@@ -324,28 +313,6 @@ struct fsg_common { ...@@ -324,28 +313,6 @@ struct fsg_common {
struct kref ref; 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;
unsigned int fsg_num_buffers;
};
struct fsg_dev { struct fsg_dev {
struct usb_function function; struct usb_function function;
struct usb_gadget *gadget; /* Copy of cdev->gadget */ struct usb_gadget *gadget; /* Copy of cdev->gadget */
...@@ -2644,12 +2611,12 @@ static void fsg_lun_release(struct device *dev) ...@@ -2644,12 +2611,12 @@ static void fsg_lun_release(struct device *dev)
/* Nothing needs to be done */ /* 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); kref_get(&common->ref);
} }
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); kref_put(&common->ref, fsg_common_release);
} }
...@@ -2664,9 +2631,9 @@ static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers) ...@@ -2664,9 +2631,9 @@ static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
return -EINVAL; return -EINVAL;
} }
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 usb_composite_dev *cdev,
struct fsg_config *cfg) struct fsg_config *cfg)
{ {
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
struct fsg_buffhd *bh; struct fsg_buffhd *bh;
...@@ -3043,62 +3010,8 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, ...@@ -3043,62 +3010,8 @@ static int fsg_bind_config(struct usb_composite_dev *cdev,
/************************* Module parameters *************************/ /************************* 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")
#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 void fsg_config_from_params(struct fsg_config *cfg,
fsg_config_from_params(struct fsg_config *cfg,
const struct fsg_module_parameters *params, const struct fsg_module_parameters *params,
unsigned int fsg_num_buffers) unsigned int fsg_num_buffers)
{ {
...@@ -3131,19 +3044,3 @@ fsg_config_from_params(struct fsg_config *cfg, ...@@ -3131,19 +3044,3 @@ fsg_config_from_params(struct fsg_config *cfg,
cfg->fsg_num_buffers = fsg_num_buffers; 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)
__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)
{
struct fsg_config cfg;
fsg_config_from_params(&cfg, params, fsg_num_buffers);
return fsg_common_init(common, cdev, &cfg);
}
#ifndef USB_F_MASS_STORAGE_H
#define USB_F_MASS_STORAGE_H
#include "storage_common.h"
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")
#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
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);
};
struct fsg_lun_config {
const char *filename;
char ro;
char removable;
char cdrom;
char nofua;
};
struct fsg_config {
unsigned nluns;
struct fsg_lun_config 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;
unsigned int fsg_num_buffers;
};
void fsg_common_get(struct fsg_common *common);
void fsg_common_put(struct fsg_common *common);
struct fsg_common *fsg_common_init(struct fsg_common *common,
struct usb_composite_dev *cdev,
struct fsg_config *cfg);
void fsg_config_from_params(struct fsg_config *cfg,
const struct fsg_module_parameters *params,
unsigned int 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)
__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)
{
struct fsg_config cfg;
fsg_config_from_params(&cfg, params, fsg_num_buffers);
return fsg_common_init(common, cdev, &cfg);
}
#endif /* USB_F_MASS_STORAGE_H */
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