f_mass_storage.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef USB_F_MASS_STORAGE_H
  2. #define USB_F_MASS_STORAGE_H
  3. #include <linux/usb/composite.h>
  4. #include "storage_common.h"
  5. struct fsg_module_parameters {
  6. char *file[FSG_MAX_LUNS];
  7. bool ro[FSG_MAX_LUNS];
  8. bool removable[FSG_MAX_LUNS];
  9. bool cdrom[FSG_MAX_LUNS];
  10. bool nofua[FSG_MAX_LUNS];
  11. unsigned int file_count, ro_count, removable_count, cdrom_count;
  12. unsigned int nofua_count;
  13. unsigned int luns; /* nluns */
  14. bool stall; /* can_stall */
  15. };
  16. #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
  17. module_param_array_named(prefix ## name, params.name, type, \
  18. &prefix ## params.name ## _count, \
  19. S_IRUGO); \
  20. MODULE_PARM_DESC(prefix ## name, desc)
  21. #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
  22. module_param_named(prefix ## name, params.name, type, \
  23. S_IRUGO); \
  24. MODULE_PARM_DESC(prefix ## name, desc)
  25. #define __FSG_MODULE_PARAMETERS(prefix, params) \
  26. _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
  27. "names of backing files or devices"); \
  28. _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
  29. "true to force read-only"); \
  30. _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
  31. "true to simulate removable media"); \
  32. _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
  33. "true to simulate CD-ROM instead of disk"); \
  34. _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
  35. "true to ignore SCSI WRITE(10,12) FUA bit"); \
  36. _FSG_MODULE_PARAM(prefix, params, luns, uint, \
  37. "number of LUNs"); \
  38. _FSG_MODULE_PARAM(prefix, params, stall, bool, \
  39. "false to prevent bulk stalls")
  40. #ifdef CONFIG_USB_GADGET_DEBUG_FILES
  41. #define FSG_MODULE_PARAMETERS(prefix, params) \
  42. __FSG_MODULE_PARAMETERS(prefix, params); \
  43. module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
  44. MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
  45. #else
  46. #define FSG_MODULE_PARAMETERS(prefix, params) \
  47. __FSG_MODULE_PARAMETERS(prefix, params)
  48. #endif
  49. struct fsg_common;
  50. /* FSF callback functions */
  51. struct fsg_lun_opts {
  52. struct config_group group;
  53. struct fsg_lun *lun;
  54. int lun_id;
  55. };
  56. struct fsg_opts {
  57. struct fsg_common *common;
  58. struct usb_function_instance func_inst;
  59. struct fsg_lun_opts lun0;
  60. struct config_group *default_groups[2];
  61. bool no_configfs; /* for legacy gadgets */
  62. /*
  63. * Read/write access to configfs attributes is handled by configfs.
  64. *
  65. * This is to protect the data from concurrent access by read/write
  66. * and create symlink/remove symlink.
  67. */
  68. struct mutex lock;
  69. int refcnt;
  70. };
  71. struct fsg_lun_config {
  72. const char *filename;
  73. char ro;
  74. char removable;
  75. char cdrom;
  76. char nofua;
  77. };
  78. struct fsg_config {
  79. unsigned nluns;
  80. struct fsg_lun_config luns[FSG_MAX_LUNS];
  81. /* Callback functions. */
  82. const struct fsg_operations *ops;
  83. /* Gadget's private data. */
  84. void *private_data;
  85. const char *vendor_name; /* 8 characters or less */
  86. const char *product_name; /* 16 characters or less */
  87. char can_stall;
  88. unsigned int fsg_num_buffers;
  89. };
  90. static inline struct fsg_opts *
  91. fsg_opts_from_func_inst(const struct usb_function_instance *fi)
  92. {
  93. return container_of(fi, struct fsg_opts, func_inst);
  94. }
  95. void fsg_common_get(struct fsg_common *common);
  96. void fsg_common_put(struct fsg_common *common);
  97. void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
  98. int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
  99. void fsg_common_free_buffers(struct fsg_common *common);
  100. int fsg_common_set_cdev(struct fsg_common *common,
  101. struct usb_composite_dev *cdev, bool can_stall);
  102. void fsg_common_remove_lun(struct fsg_lun *lun);
  103. void fsg_common_remove_luns(struct fsg_common *common);
  104. int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
  105. unsigned int id, const char *name,
  106. const char **name_pfx);
  107. int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
  108. void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
  109. const char *pn);
  110. void fsg_config_from_params(struct fsg_config *cfg,
  111. const struct fsg_module_parameters *params,
  112. unsigned int fsg_num_buffers);
  113. #endif /* USB_F_MASS_STORAGE_H */