tcm.h 2.8 KB

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