tcm_usb_gadget.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef __TARGET_USB_GADGET_H__
  2. #define __TARGET_USB_GADGET_H__
  3. #include <linux/kref.h>
  4. /* #include <linux/usb/uas.h> */
  5. #include <linux/usb/composite.h>
  6. #include <linux/usb/uas.h>
  7. #include <linux/usb/storage.h>
  8. #include <target/target_core_base.h>
  9. #include <target/target_core_fabric.h>
  10. #define USBG_NAMELEN 32
  11. #define fuas_to_gadget(f) (f->function.config->cdev->gadget)
  12. #define UASP_SS_EP_COMP_LOG_STREAMS 4
  13. #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS)
  14. enum {
  15. USB_G_STR_CONFIG = USB_GADGET_FIRST_AVAIL_IDX,
  16. USB_G_STR_INT_UAS,
  17. USB_G_STR_INT_BBB,
  18. };
  19. #define USB_G_ALT_INT_BBB 0
  20. #define USB_G_ALT_INT_UAS 1
  21. struct tcm_usbg_nexus {
  22. struct se_session *tvn_se_sess;
  23. };
  24. struct usbg_tpg {
  25. struct mutex tpg_mutex;
  26. /* SAS port target portal group tag for TCM */
  27. u16 tport_tpgt;
  28. /* Pointer back to usbg_tport */
  29. struct usbg_tport *tport;
  30. struct workqueue_struct *workqueue;
  31. /* Returned by usbg_make_tpg() */
  32. struct se_portal_group se_tpg;
  33. u32 gadget_connect;
  34. struct tcm_usbg_nexus *tpg_nexus;
  35. atomic_t tpg_port_count;
  36. };
  37. struct usbg_tport {
  38. /* Binary World Wide unique Port Name for SAS Target port */
  39. u64 tport_wwpn;
  40. /* ASCII formatted WWPN for SAS Target port */
  41. char tport_name[USBG_NAMELEN];
  42. /* Returned by usbg_make_tport() */
  43. struct se_wwn tport_wwn;
  44. };
  45. enum uas_state {
  46. UASP_SEND_DATA,
  47. UASP_RECEIVE_DATA,
  48. UASP_SEND_STATUS,
  49. UASP_QUEUE_COMMAND,
  50. };
  51. #define USBG_MAX_CMD 64
  52. struct usbg_cmd {
  53. /* common */
  54. u8 cmd_buf[USBG_MAX_CMD];
  55. u32 data_len;
  56. struct work_struct work;
  57. int unpacked_lun;
  58. struct se_cmd se_cmd;
  59. void *data_buf; /* used if no sg support available */
  60. struct f_uas *fu;
  61. struct completion write_complete;
  62. struct kref ref;
  63. /* UAS only */
  64. u16 tag;
  65. u16 prio_attr;
  66. struct sense_iu sense_iu;
  67. enum uas_state state;
  68. struct uas_stream *stream;
  69. /* BOT only */
  70. __le32 bot_tag;
  71. unsigned int csw_code;
  72. unsigned is_read:1;
  73. };
  74. struct uas_stream {
  75. struct usb_request *req_in;
  76. struct usb_request *req_out;
  77. struct usb_request *req_status;
  78. };
  79. struct usbg_cdb {
  80. struct usb_request *req;
  81. void *buf;
  82. };
  83. struct bot_status {
  84. struct usb_request *req;
  85. struct bulk_cs_wrap csw;
  86. };
  87. struct f_uas {
  88. struct usbg_tpg *tpg;
  89. struct usb_function function;
  90. u16 iface;
  91. u32 flags;
  92. #define USBG_ENABLED (1 << 0)
  93. #define USBG_IS_UAS (1 << 1)
  94. #define USBG_USE_STREAMS (1 << 2)
  95. #define USBG_IS_BOT (1 << 3)
  96. #define USBG_BOT_CMD_PEND (1 << 4)
  97. struct usbg_cdb cmd;
  98. struct usb_ep *ep_in;
  99. struct usb_ep *ep_out;
  100. /* UAS */
  101. struct usb_ep *ep_status;
  102. struct usb_ep *ep_cmd;
  103. struct uas_stream stream[UASP_SS_EP_COMP_NUM_STREAMS];
  104. /* BOT */
  105. struct bot_status bot_status;
  106. struct usb_request *bot_req_in;
  107. struct usb_request *bot_req_out;
  108. };
  109. extern struct usbg_tpg *the_only_tpg_I_currently_have;
  110. #endif