tcm_usb_gadget.h 3.1 KB

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