tcm_usb_gadget.h 3.1 KB

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