Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef USB_F_MASS_STORAGE_H
  3#define USB_F_MASS_STORAGE_H
  4
  5#include <linux/usb/composite.h>
  6#include "storage_common.h"
  7
  8struct fsg_module_parameters {
  9	char		*file[FSG_MAX_LUNS];
 10	bool		ro[FSG_MAX_LUNS];
 11	bool		removable[FSG_MAX_LUNS];
 12	bool		cdrom[FSG_MAX_LUNS];
 13	bool		nofua[FSG_MAX_LUNS];
 14
 15	unsigned int	file_count, ro_count, removable_count, cdrom_count;
 16	unsigned int	nofua_count;
 17	unsigned int	luns;	/* nluns */
 18	bool		stall;	/* can_stall */
 19};
 20
 21#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)	\
 22	module_param_array_named(prefix ## name, params.name, type,	\
 23				 &prefix ## params.name ## _count,	\
 24				 S_IRUGO);				\
 25	MODULE_PARM_DESC(prefix ## name, desc)
 26
 27#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)		\
 28	module_param_named(prefix ## name, params.name, type,		\
 29			   S_IRUGO);					\
 30	MODULE_PARM_DESC(prefix ## name, desc)
 31
 32#define __FSG_MODULE_PARAMETERS(prefix, params)				\
 33	_FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp,		\
 34				"names of backing files or devices");	\
 35	_FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool,		\
 36				"true to force read-only");		\
 37	_FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool,	\
 38				"true to simulate removable media");	\
 39	_FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool,		\
 40				"true to simulate CD-ROM instead of disk"); \
 41	_FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool,		\
 42				"true to ignore SCSI WRITE(10,12) FUA bit"); \
 43	_FSG_MODULE_PARAM(prefix, params, luns, uint,			\
 44			  "number of LUNs");				\
 45	_FSG_MODULE_PARAM(prefix, params, stall, bool,			\
 46			  "false to prevent bulk stalls")
 47
 48#ifdef CONFIG_USB_GADGET_DEBUG_FILES
 49
 50#define FSG_MODULE_PARAMETERS(prefix, params)				\
 51	__FSG_MODULE_PARAMETERS(prefix, params);			\
 52	module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
 53	MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
 54#else
 55
 56#define FSG_MODULE_PARAMETERS(prefix, params)				\
 57	__FSG_MODULE_PARAMETERS(prefix, params)
 58
 59#endif
 60
 61struct fsg_common;
 62
 63/* FSF callback functions */
 
 
 
 
 
 
 
 
 
 
 
 64struct fsg_lun_opts {
 65	struct config_group group;
 66	struct fsg_lun *lun;
 67	int lun_id;
 68};
 69
 70struct fsg_opts {
 71	struct fsg_common *common;
 72	struct usb_function_instance func_inst;
 73	struct fsg_lun_opts lun0;
 74	struct config_group *default_groups[2];
 75	bool no_configfs; /* for legacy gadgets */
 76
 77	/*
 78	 * Read/write access to configfs attributes is handled by configfs.
 79	 *
 80	 * This is to protect the data from concurrent access by read/write
 81	 * and create symlink/remove symlink.
 82	 */
 83	struct mutex			lock;
 84	int				refcnt;
 85};
 86
 87struct fsg_lun_config {
 88	const char *filename;
 89	char ro;
 90	char removable;
 91	char cdrom;
 92	char nofua;
 93	char inquiry_string[INQUIRY_STRING_LEN];
 94};
 95
 96struct fsg_config {
 97	unsigned nluns;
 98	struct fsg_lun_config luns[FSG_MAX_LUNS];
 99
100	/* Callback functions. */
101	const struct fsg_operations	*ops;
102	/* Gadget's private data. */
103	void			*private_data;
104
105	const char *vendor_name;		/*  8 characters or less */
106	const char *product_name;		/* 16 characters or less */
107
108	char			can_stall;
109	unsigned int		fsg_num_buffers;
110};
111
112static inline struct fsg_opts *
113fsg_opts_from_func_inst(const struct usb_function_instance *fi)
114{
115	return container_of(fi, struct fsg_opts, func_inst);
116}
117
 
 
 
 
118void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
119
120int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
121
122void fsg_common_free_buffers(struct fsg_common *common);
123
124int fsg_common_set_cdev(struct fsg_common *common,
125			struct usb_composite_dev *cdev, bool can_stall);
126
127void fsg_common_remove_lun(struct fsg_lun *lun);
128
129void fsg_common_remove_luns(struct fsg_common *common);
 
 
 
130
131int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
132			  unsigned int id, const char *name,
133			  const char **name_pfx);
134
135int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
136
137void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
138				   const char *pn);
139
140void fsg_config_from_params(struct fsg_config *cfg,
141			    const struct fsg_module_parameters *params,
142			    unsigned int fsg_num_buffers);
143
144#endif /* USB_F_MASS_STORAGE_H */
v4.10.11
 
  1#ifndef USB_F_MASS_STORAGE_H
  2#define USB_F_MASS_STORAGE_H
  3
  4#include <linux/usb/composite.h>
  5#include "storage_common.h"
  6
  7struct fsg_module_parameters {
  8	char		*file[FSG_MAX_LUNS];
  9	bool		ro[FSG_MAX_LUNS];
 10	bool		removable[FSG_MAX_LUNS];
 11	bool		cdrom[FSG_MAX_LUNS];
 12	bool		nofua[FSG_MAX_LUNS];
 13
 14	unsigned int	file_count, ro_count, removable_count, cdrom_count;
 15	unsigned int	nofua_count;
 16	unsigned int	luns;	/* nluns */
 17	bool		stall;	/* can_stall */
 18};
 19
 20#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)	\
 21	module_param_array_named(prefix ## name, params.name, type,	\
 22				 &prefix ## params.name ## _count,	\
 23				 S_IRUGO);				\
 24	MODULE_PARM_DESC(prefix ## name, desc)
 25
 26#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)		\
 27	module_param_named(prefix ## name, params.name, type,		\
 28			   S_IRUGO);					\
 29	MODULE_PARM_DESC(prefix ## name, desc)
 30
 31#define __FSG_MODULE_PARAMETERS(prefix, params)				\
 32	_FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp,		\
 33				"names of backing files or devices");	\
 34	_FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool,		\
 35				"true to force read-only");		\
 36	_FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool,	\
 37				"true to simulate removable media");	\
 38	_FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool,		\
 39				"true to simulate CD-ROM instead of disk"); \
 40	_FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool,		\
 41				"true to ignore SCSI WRITE(10,12) FUA bit"); \
 42	_FSG_MODULE_PARAM(prefix, params, luns, uint,			\
 43			  "number of LUNs");				\
 44	_FSG_MODULE_PARAM(prefix, params, stall, bool,			\
 45			  "false to prevent bulk stalls")
 46
 47#ifdef CONFIG_USB_GADGET_DEBUG_FILES
 48
 49#define FSG_MODULE_PARAMETERS(prefix, params)				\
 50	__FSG_MODULE_PARAMETERS(prefix, params);			\
 51	module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
 52	MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
 53#else
 54
 55#define FSG_MODULE_PARAMETERS(prefix, params)				\
 56	__FSG_MODULE_PARAMETERS(prefix, params)
 57
 58#endif
 59
 60struct fsg_common;
 61
 62/* FSF callback functions */
 63struct fsg_operations {
 64	/*
 65	 * Callback function to call when thread exits.  If no
 66	 * callback is set or it returns value lower then zero MSF
 67	 * will force eject all LUNs it operates on (including those
 68	 * marked as non-removable or with prevent_medium_removal flag
 69	 * set).
 70	 */
 71	int (*thread_exits)(struct fsg_common *common);
 72};
 73
 74struct fsg_lun_opts {
 75	struct config_group group;
 76	struct fsg_lun *lun;
 77	int lun_id;
 78};
 79
 80struct fsg_opts {
 81	struct fsg_common *common;
 82	struct usb_function_instance func_inst;
 83	struct fsg_lun_opts lun0;
 84	struct config_group *default_groups[2];
 85	bool no_configfs; /* for legacy gadgets */
 86
 87	/*
 88	 * Read/write access to configfs attributes is handled by configfs.
 89	 *
 90	 * This is to protect the data from concurrent access by read/write
 91	 * and create symlink/remove symlink.
 92	 */
 93	struct mutex			lock;
 94	int				refcnt;
 95};
 96
 97struct fsg_lun_config {
 98	const char *filename;
 99	char ro;
100	char removable;
101	char cdrom;
102	char nofua;
103	char inquiry_string[INQUIRY_STRING_LEN];
104};
105
106struct fsg_config {
107	unsigned nluns;
108	struct fsg_lun_config luns[FSG_MAX_LUNS];
109
110	/* Callback functions. */
111	const struct fsg_operations	*ops;
112	/* Gadget's private data. */
113	void			*private_data;
114
115	const char *vendor_name;		/*  8 characters or less */
116	const char *product_name;		/* 16 characters or less */
117
118	char			can_stall;
119	unsigned int		fsg_num_buffers;
120};
121
122static inline struct fsg_opts *
123fsg_opts_from_func_inst(const struct usb_function_instance *fi)
124{
125	return container_of(fi, struct fsg_opts, func_inst);
126}
127
128void fsg_common_get(struct fsg_common *common);
129
130void fsg_common_put(struct fsg_common *common);
131
132void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
133
134int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
135
136void fsg_common_free_buffers(struct fsg_common *common);
137
138int fsg_common_set_cdev(struct fsg_common *common,
139			struct usb_composite_dev *cdev, bool can_stall);
140
141void fsg_common_remove_lun(struct fsg_lun *lun);
142
143void fsg_common_remove_luns(struct fsg_common *common);
144
145void fsg_common_set_ops(struct fsg_common *common,
146			const struct fsg_operations *ops);
147
148int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
149			  unsigned int id, const char *name,
150			  const char **name_pfx);
151
152int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
153
154void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
155				   const char *pn);
156
157void fsg_config_from_params(struct fsg_config *cfg,
158			    const struct fsg_module_parameters *params,
159			    unsigned int fsg_num_buffers);
160
161#endif /* USB_F_MASS_STORAGE_H */