f_mass_storage.h 4.6 KB

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