tcm_usb_gadget.h 3.2 KB

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