inet: frag: enforce memory limits earlier
[linux/fpc-iii.git] / drivers / usb / gadget / function / f_mass_storage.h
blobdc05ca0c435969037811c75ac2b0e094cb66c155
1 #ifndef USB_F_MASS_STORAGE_H
2 #define USB_F_MASS_STORAGE_H
4 #include <linux/usb/composite.h>
5 #include "storage_common.h"
7 struct 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];
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 */
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)
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)
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")
47 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
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
55 #define FSG_MODULE_PARAMETERS(prefix, params) \
56 __FSG_MODULE_PARAMETERS(prefix, params)
58 #endif
60 struct fsg_common;
62 /* FSF callback functions */
63 struct fsg_lun_opts {
64 struct config_group group;
65 struct fsg_lun *lun;
66 int lun_id;
69 struct fsg_opts {
70 struct fsg_common *common;
71 struct usb_function_instance func_inst;
72 struct fsg_lun_opts lun0;
73 struct config_group *default_groups[2];
74 bool no_configfs; /* for legacy gadgets */
77 * Read/write access to configfs attributes is handled by configfs.
79 * This is to protect the data from concurrent access by read/write
80 * and create symlink/remove symlink.
82 struct mutex lock;
83 int refcnt;
86 struct fsg_lun_config {
87 const char *filename;
88 char ro;
89 char removable;
90 char cdrom;
91 char nofua;
92 char inquiry_string[INQUIRY_STRING_LEN];
95 struct fsg_config {
96 unsigned nluns;
97 struct fsg_lun_config luns[FSG_MAX_LUNS];
99 /* Callback functions. */
100 const struct fsg_operations *ops;
101 /* Gadget's private data. */
102 void *private_data;
104 const char *vendor_name; /* 8 characters or less */
105 const char *product_name; /* 16 characters or less */
107 char can_stall;
108 unsigned int fsg_num_buffers;
111 static inline struct fsg_opts *
112 fsg_opts_from_func_inst(const struct usb_function_instance *fi)
114 return container_of(fi, struct fsg_opts, func_inst);
117 void fsg_common_get(struct fsg_common *common);
119 void fsg_common_put(struct fsg_common *common);
121 void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
123 int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
125 void fsg_common_free_buffers(struct fsg_common *common);
127 int fsg_common_set_cdev(struct fsg_common *common,
128 struct usb_composite_dev *cdev, bool can_stall);
130 void fsg_common_remove_lun(struct fsg_lun *lun);
132 void fsg_common_remove_luns(struct fsg_common *common);
134 int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
135 unsigned int id, const char *name,
136 const char **name_pfx);
138 int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
140 void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
141 const char *pn);
143 void fsg_config_from_params(struct fsg_config *cfg,
144 const struct fsg_module_parameters *params,
145 unsigned int fsg_num_buffers);
147 #endif /* USB_F_MASS_STORAGE_H */