usb: gadget: f_mass_storage: create fsg_common_run_thread for use in fsg_common_init
[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
4#include "storage_common.h"
5
6struct fsg_module_parameters {
7 char *file[FSG_MAX_LUNS];
8 bool ro[FSG_MAX_LUNS];
9 bool removable[FSG_MAX_LUNS];
10 bool cdrom[FSG_MAX_LUNS];
11 bool nofua[FSG_MAX_LUNS];
12
13 unsigned int file_count, ro_count, removable_count, cdrom_count;
14 unsigned int nofua_count;
15 unsigned int luns; /* nluns */
16 bool stall; /* can_stall */
17};
18
19#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
20 module_param_array_named(prefix ## name, params.name, type, \
21 &prefix ## params.name ## _count, \
22 S_IRUGO); \
23 MODULE_PARM_DESC(prefix ## name, desc)
24
25#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
26 module_param_named(prefix ## name, params.name, type, \
27 S_IRUGO); \
28 MODULE_PARM_DESC(prefix ## name, desc)
29
30#define __FSG_MODULE_PARAMETERS(prefix, params) \
31 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
32 "names of backing files or devices"); \
33 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
34 "true to force read-only"); \
35 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
36 "true to simulate removable media"); \
37 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
38 "true to simulate CD-ROM instead of disk"); \
39 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
40 "true to ignore SCSI WRITE(10,12) FUA bit"); \
41 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
42 "number of LUNs"); \
43 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
44 "false to prevent bulk stalls")
45
46#ifdef CONFIG_USB_GADGET_DEBUG_FILES
47
48#define FSG_MODULE_PARAMETERS(prefix, params) \
49 __FSG_MODULE_PARAMETERS(prefix, params); \
50 module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
51 MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
52#else
53
54#define FSG_MODULE_PARAMETERS(prefix, params) \
55 __FSG_MODULE_PARAMETERS(prefix, params)
56
57#endif
58
59struct fsg_common;
60
61/* FSF callback functions */
62struct fsg_operations {
63 /*
64 * Callback function to call when thread exits. If no
65 * callback is set or it returns value lower then zero MSF
66 * will force eject all LUNs it operates on (including those
67 * marked as non-removable or with prevent_medium_removal flag
68 * set).
69 */
70 int (*thread_exits)(struct fsg_common *common);
71};
72
73struct fsg_lun_config {
74 const char *filename;
75 char ro;
76 char removable;
77 char cdrom;
78 char nofua;
79};
80
81struct fsg_config {
82 unsigned nluns;
83 struct fsg_lun_config luns[FSG_MAX_LUNS];
84
85 /* Callback functions. */
86 const struct fsg_operations *ops;
87 /* Gadget's private data. */
88 void *private_data;
89
90 const char *vendor_name; /* 8 characters or less */
91 const char *product_name; /* 16 characters or less */
92
93 char can_stall;
94 unsigned int fsg_num_buffers;
95};
96
97void fsg_common_get(struct fsg_common *common);
98
99void fsg_common_put(struct fsg_common *common);
100
101struct fsg_common *fsg_common_init(struct fsg_common *common,
102 struct usb_composite_dev *cdev,
103 struct fsg_config *cfg);
104
bd528d4e
AP
105void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
106
6313caac
AP
107int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
108
a891d7a3
AP
109int fsg_common_set_cdev(struct fsg_common *common,
110 struct usb_composite_dev *cdev, bool can_stall);
111
70634170
AP
112void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs);
113
114void fsg_common_remove_luns(struct fsg_common *common);
115
116void fsg_common_free_luns(struct fsg_common *common);
117
118int fsg_common_set_nluns(struct fsg_common *common, int nluns);
119
b27c08c9
AP
120int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
121 unsigned int id, const char *name,
122 const char **name_pfx);
123
124int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
125
23682e3c
AP
126void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
127 const char *pn);
128
5de862d7
AP
129int fsg_common_run_thread(struct fsg_common *common);
130
f3fed367
AP
131void fsg_config_from_params(struct fsg_config *cfg,
132 const struct fsg_module_parameters *params,
133 unsigned int fsg_num_buffers);
134
135static inline struct fsg_common *
136fsg_common_from_params(struct fsg_common *common,
137 struct usb_composite_dev *cdev,
138 const struct fsg_module_parameters *params,
139 unsigned int fsg_num_buffers)
140 __attribute__((unused));
141static inline struct fsg_common *
142fsg_common_from_params(struct fsg_common *common,
143 struct usb_composite_dev *cdev,
144 const struct fsg_module_parameters *params,
145 unsigned int fsg_num_buffers)
146{
147 struct fsg_config cfg;
148 fsg_config_from_params(&cfg, params, fsg_num_buffers);
149 return fsg_common_init(common, cdev, &cfg);
150}
151
152#endif /* USB_F_MASS_STORAGE_H */
This page took 0.061872 seconds and 5 git commands to generate.