usb: gadget: f_mass_storage: convert to new function interface with backward compatib...
[deliverable/linux.git] / drivers / usb / gadget / f_mass_storage.h
CommitLineData
f3fed367
AP
1#ifndef USB_F_MASS_STORAGE_H
2#define USB_F_MASS_STORAGE_H
3
e5eaa0dc 4#include <linux/usb/composite.h>
f3fed367
AP
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
e5eaa0dc
AP
74struct fsg_opts {
75 struct fsg_common *common;
76 struct usb_function_instance func_inst;
77 bool no_configfs; /* for legacy gadgets */
78};
79
f3fed367
AP
80struct fsg_lun_config {
81 const char *filename;
82 char ro;
83 char removable;
84 char cdrom;
85 char nofua;
86};
87
88struct fsg_config {
89 unsigned nluns;
90 struct fsg_lun_config luns[FSG_MAX_LUNS];
91
92 /* Callback functions. */
93 const struct fsg_operations *ops;
94 /* Gadget's private data. */
95 void *private_data;
96
97 const char *vendor_name; /* 8 characters or less */
98 const char *product_name; /* 16 characters or less */
99
100 char can_stall;
101 unsigned int fsg_num_buffers;
102};
103
e5eaa0dc
AP
104static inline struct fsg_opts *
105fsg_opts_from_func_inst(const struct usb_function_instance *fi)
106{
107 return container_of(fi, struct fsg_opts, func_inst);
108}
109
f3fed367
AP
110void fsg_common_get(struct fsg_common *common);
111
112void fsg_common_put(struct fsg_common *common);
113
114struct fsg_common *fsg_common_init(struct fsg_common *common,
115 struct usb_composite_dev *cdev,
116 struct fsg_config *cfg);
117
bd528d4e
AP
118void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
119
6313caac
AP
120int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
121
e5eaa0dc
AP
122void fsg_common_free_buffers(struct fsg_common *common);
123
a891d7a3
AP
124int fsg_common_set_cdev(struct fsg_common *common,
125 struct usb_composite_dev *cdev, bool can_stall);
126
70634170
AP
127void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs);
128
129void fsg_common_remove_luns(struct fsg_common *common);
130
131void fsg_common_free_luns(struct fsg_common *common);
132
133int fsg_common_set_nluns(struct fsg_common *common, int nluns);
134
b27c08c9
AP
135int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
136 unsigned int id, const char *name,
137 const char **name_pfx);
138
139int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
140
23682e3c
AP
141void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
142 const char *pn);
143
5de862d7
AP
144int fsg_common_run_thread(struct fsg_common *common);
145
f3fed367
AP
146void fsg_config_from_params(struct fsg_config *cfg,
147 const struct fsg_module_parameters *params,
148 unsigned int fsg_num_buffers);
149
150static inline struct fsg_common *
151fsg_common_from_params(struct fsg_common *common,
152 struct usb_composite_dev *cdev,
153 const struct fsg_module_parameters *params,
154 unsigned int fsg_num_buffers)
155 __attribute__((unused));
156static inline struct fsg_common *
157fsg_common_from_params(struct fsg_common *common,
158 struct usb_composite_dev *cdev,
159 const struct fsg_module_parameters *params,
160 unsigned int fsg_num_buffers)
161{
162 struct fsg_config cfg;
163 fsg_config_from_params(&cfg, params, fsg_num_buffers);
164 return fsg_common_init(common, cdev, &cfg);
165}
166
167#endif /* USB_F_MASS_STORAGE_H */
This page took 0.033125 seconds and 5 git commands to generate.