f_mass_storage.h 4.1 KB

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