1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
200a2430fSAndrzej Pietrasiewicz #ifndef USB_F_MASS_STORAGE_H
300a2430fSAndrzej Pietrasiewicz #define USB_F_MASS_STORAGE_H
400a2430fSAndrzej Pietrasiewicz
500a2430fSAndrzej Pietrasiewicz #include <linux/usb/composite.h>
600a2430fSAndrzej Pietrasiewicz #include "storage_common.h"
700a2430fSAndrzej Pietrasiewicz
800a2430fSAndrzej Pietrasiewicz struct fsg_module_parameters {
900a2430fSAndrzej Pietrasiewicz char *file[FSG_MAX_LUNS];
1000a2430fSAndrzej Pietrasiewicz bool ro[FSG_MAX_LUNS];
1100a2430fSAndrzej Pietrasiewicz bool removable[FSG_MAX_LUNS];
1200a2430fSAndrzej Pietrasiewicz bool cdrom[FSG_MAX_LUNS];
1300a2430fSAndrzej Pietrasiewicz bool nofua[FSG_MAX_LUNS];
1400a2430fSAndrzej Pietrasiewicz
1500a2430fSAndrzej Pietrasiewicz unsigned int file_count, ro_count, removable_count, cdrom_count;
1600a2430fSAndrzej Pietrasiewicz unsigned int nofua_count;
1700a2430fSAndrzej Pietrasiewicz unsigned int luns; /* nluns */
1800a2430fSAndrzej Pietrasiewicz bool stall; /* can_stall */
1900a2430fSAndrzej Pietrasiewicz };
2000a2430fSAndrzej Pietrasiewicz
2100a2430fSAndrzej Pietrasiewicz #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
2200a2430fSAndrzej Pietrasiewicz module_param_array_named(prefix ## name, params.name, type, \
2300a2430fSAndrzej Pietrasiewicz &prefix ## params.name ## _count, \
2400a2430fSAndrzej Pietrasiewicz S_IRUGO); \
2500a2430fSAndrzej Pietrasiewicz MODULE_PARM_DESC(prefix ## name, desc)
2600a2430fSAndrzej Pietrasiewicz
2700a2430fSAndrzej Pietrasiewicz #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
2800a2430fSAndrzej Pietrasiewicz module_param_named(prefix ## name, params.name, type, \
2900a2430fSAndrzej Pietrasiewicz S_IRUGO); \
3000a2430fSAndrzej Pietrasiewicz MODULE_PARM_DESC(prefix ## name, desc)
3100a2430fSAndrzej Pietrasiewicz
3200a2430fSAndrzej Pietrasiewicz #define __FSG_MODULE_PARAMETERS(prefix, params) \
3300a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
3400a2430fSAndrzej Pietrasiewicz "names of backing files or devices"); \
3500a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
3600a2430fSAndrzej Pietrasiewicz "true to force read-only"); \
3700a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
3800a2430fSAndrzej Pietrasiewicz "true to simulate removable media"); \
3900a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
4000a2430fSAndrzej Pietrasiewicz "true to simulate CD-ROM instead of disk"); \
4100a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
4200a2430fSAndrzej Pietrasiewicz "true to ignore SCSI WRITE(10,12) FUA bit"); \
4300a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM(prefix, params, luns, uint, \
4400a2430fSAndrzej Pietrasiewicz "number of LUNs"); \
4500a2430fSAndrzej Pietrasiewicz _FSG_MODULE_PARAM(prefix, params, stall, bool, \
4600a2430fSAndrzej Pietrasiewicz "false to prevent bulk stalls")
4700a2430fSAndrzej Pietrasiewicz
4800a2430fSAndrzej Pietrasiewicz #ifdef CONFIG_USB_GADGET_DEBUG_FILES
4900a2430fSAndrzej Pietrasiewicz
5000a2430fSAndrzej Pietrasiewicz #define FSG_MODULE_PARAMETERS(prefix, params) \
5100a2430fSAndrzej Pietrasiewicz __FSG_MODULE_PARAMETERS(prefix, params); \
5200a2430fSAndrzej Pietrasiewicz module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
5300a2430fSAndrzej Pietrasiewicz MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
5400a2430fSAndrzej Pietrasiewicz #else
5500a2430fSAndrzej Pietrasiewicz
5600a2430fSAndrzej Pietrasiewicz #define FSG_MODULE_PARAMETERS(prefix, params) \
5700a2430fSAndrzej Pietrasiewicz __FSG_MODULE_PARAMETERS(prefix, params)
5800a2430fSAndrzej Pietrasiewicz
5900a2430fSAndrzej Pietrasiewicz #endif
6000a2430fSAndrzej Pietrasiewicz
6100a2430fSAndrzej Pietrasiewicz struct fsg_common;
6200a2430fSAndrzej Pietrasiewicz
6300a2430fSAndrzej Pietrasiewicz /* FSF callback functions */
6400a2430fSAndrzej Pietrasiewicz struct fsg_lun_opts {
6500a2430fSAndrzej Pietrasiewicz struct config_group group;
6600a2430fSAndrzej Pietrasiewicz struct fsg_lun *lun;
6700a2430fSAndrzej Pietrasiewicz int lun_id;
6800a2430fSAndrzej Pietrasiewicz };
6900a2430fSAndrzej Pietrasiewicz
7000a2430fSAndrzej Pietrasiewicz struct fsg_opts {
7100a2430fSAndrzej Pietrasiewicz struct fsg_common *common;
7200a2430fSAndrzej Pietrasiewicz struct usb_function_instance func_inst;
7300a2430fSAndrzej Pietrasiewicz struct fsg_lun_opts lun0;
7400a2430fSAndrzej Pietrasiewicz struct config_group *default_groups[2];
7500a2430fSAndrzej Pietrasiewicz bool no_configfs; /* for legacy gadgets */
7600a2430fSAndrzej Pietrasiewicz
7700a2430fSAndrzej Pietrasiewicz /*
7800a2430fSAndrzej Pietrasiewicz * Read/write access to configfs attributes is handled by configfs.
7900a2430fSAndrzej Pietrasiewicz *
8000a2430fSAndrzej Pietrasiewicz * This is to protect the data from concurrent access by read/write
8100a2430fSAndrzej Pietrasiewicz * and create symlink/remove symlink.
8200a2430fSAndrzej Pietrasiewicz */
8300a2430fSAndrzej Pietrasiewicz struct mutex lock;
8400a2430fSAndrzej Pietrasiewicz int refcnt;
8500a2430fSAndrzej Pietrasiewicz };
8600a2430fSAndrzej Pietrasiewicz
8700a2430fSAndrzej Pietrasiewicz struct fsg_lun_config {
8800a2430fSAndrzej Pietrasiewicz const char *filename;
8900a2430fSAndrzej Pietrasiewicz char ro;
9000a2430fSAndrzej Pietrasiewicz char removable;
9100a2430fSAndrzej Pietrasiewicz char cdrom;
9200a2430fSAndrzej Pietrasiewicz char nofua;
936ac47090SPhilipp Gesang char inquiry_string[INQUIRY_STRING_LEN];
9400a2430fSAndrzej Pietrasiewicz };
9500a2430fSAndrzej Pietrasiewicz
9600a2430fSAndrzej Pietrasiewicz struct fsg_config {
9700a2430fSAndrzej Pietrasiewicz unsigned nluns;
9800a2430fSAndrzej Pietrasiewicz struct fsg_lun_config luns[FSG_MAX_LUNS];
9900a2430fSAndrzej Pietrasiewicz
10000a2430fSAndrzej Pietrasiewicz /* Callback functions. */
10100a2430fSAndrzej Pietrasiewicz const struct fsg_operations *ops;
10200a2430fSAndrzej Pietrasiewicz /* Gadget's private data. */
10300a2430fSAndrzej Pietrasiewicz void *private_data;
10400a2430fSAndrzej Pietrasiewicz
10500a2430fSAndrzej Pietrasiewicz const char *vendor_name; /* 8 characters or less */
10600a2430fSAndrzej Pietrasiewicz const char *product_name; /* 16 characters or less */
10700a2430fSAndrzej Pietrasiewicz
10800a2430fSAndrzej Pietrasiewicz char can_stall;
10900a2430fSAndrzej Pietrasiewicz unsigned int fsg_num_buffers;
11000a2430fSAndrzej Pietrasiewicz };
11100a2430fSAndrzej Pietrasiewicz
11200a2430fSAndrzej Pietrasiewicz static inline struct fsg_opts *
fsg_opts_from_func_inst(const struct usb_function_instance * fi)11300a2430fSAndrzej Pietrasiewicz fsg_opts_from_func_inst(const struct usb_function_instance *fi)
11400a2430fSAndrzej Pietrasiewicz {
11500a2430fSAndrzej Pietrasiewicz return container_of(fi, struct fsg_opts, func_inst);
11600a2430fSAndrzej Pietrasiewicz }
11700a2430fSAndrzej Pietrasiewicz
11800a2430fSAndrzej Pietrasiewicz void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
11900a2430fSAndrzej Pietrasiewicz
12000a2430fSAndrzej Pietrasiewicz int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
12100a2430fSAndrzej Pietrasiewicz
12200a2430fSAndrzej Pietrasiewicz void fsg_common_free_buffers(struct fsg_common *common);
12300a2430fSAndrzej Pietrasiewicz
12400a2430fSAndrzej Pietrasiewicz int fsg_common_set_cdev(struct fsg_common *common,
12500a2430fSAndrzej Pietrasiewicz struct usb_composite_dev *cdev, bool can_stall);
12600a2430fSAndrzej Pietrasiewicz
1275542f58cSKrzysztof Opasiak void fsg_common_remove_lun(struct fsg_lun *lun);
12800a2430fSAndrzej Pietrasiewicz
12900a2430fSAndrzej Pietrasiewicz void fsg_common_remove_luns(struct fsg_common *common);
13000a2430fSAndrzej Pietrasiewicz
13100a2430fSAndrzej Pietrasiewicz int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
13200a2430fSAndrzej Pietrasiewicz unsigned int id, const char *name,
13300a2430fSAndrzej Pietrasiewicz const char **name_pfx);
13400a2430fSAndrzej Pietrasiewicz
13500a2430fSAndrzej Pietrasiewicz int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
13600a2430fSAndrzej Pietrasiewicz
13700a2430fSAndrzej Pietrasiewicz void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
13800a2430fSAndrzej Pietrasiewicz const char *pn);
13900a2430fSAndrzej Pietrasiewicz
14000a2430fSAndrzej Pietrasiewicz void fsg_config_from_params(struct fsg_config *cfg,
14100a2430fSAndrzej Pietrasiewicz const struct fsg_module_parameters *params,
14200a2430fSAndrzej Pietrasiewicz unsigned int fsg_num_buffers);
14300a2430fSAndrzej Pietrasiewicz
14400a2430fSAndrzej Pietrasiewicz #endif /* USB_F_MASS_STORAGE_H */
145