tcm_vhost.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #define TCM_VHOST_VERSION "v0.1"
  2. #define TCM_VHOST_NAMELEN 256
  3. #define TCM_VHOST_MAX_CDB_SIZE 32
  4. struct tcm_vhost_cmd {
  5. /* Descriptor from vhost_get_vq_desc() for virt_queue segment */
  6. int tvc_vq_desc;
  7. /* virtio-scsi initiator task attribute */
  8. int tvc_task_attr;
  9. /* virtio-scsi initiator data direction */
  10. enum dma_data_direction tvc_data_direction;
  11. /* Expected data transfer length from virtio-scsi header */
  12. u32 tvc_exp_data_len;
  13. /* The Tag from include/linux/virtio_scsi.h:struct virtio_scsi_cmd_req */
  14. u64 tvc_tag;
  15. /* The number of scatterlists associated with this cmd */
  16. u32 tvc_sgl_count;
  17. /* Saved unpacked SCSI LUN for tcm_vhost_submission_work() */
  18. u32 tvc_lun;
  19. /* Pointer to the SGL formatted memory from virtio-scsi */
  20. struct scatterlist *tvc_sgl;
  21. /* Pointer to response */
  22. struct virtio_scsi_cmd_resp __user *tvc_resp;
  23. /* Pointer to vhost_scsi for our device */
  24. struct vhost_scsi *tvc_vhost;
  25. /* Pointer to vhost_virtqueue for the cmd */
  26. struct vhost_virtqueue *tvc_vq;
  27. /* Pointer to vhost nexus memory */
  28. struct tcm_vhost_nexus *tvc_nexus;
  29. /* The TCM I/O descriptor that is accessed via container_of() */
  30. struct se_cmd tvc_se_cmd;
  31. /* work item used for cmwq dispatch to tcm_vhost_submission_work() */
  32. struct work_struct work;
  33. /* Copy of the incoming SCSI command descriptor block (CDB) */
  34. unsigned char tvc_cdb[TCM_VHOST_MAX_CDB_SIZE];
  35. /* Sense buffer that will be mapped into outgoing status */
  36. unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER];
  37. /* Completed commands list, serviced from vhost worker thread */
  38. struct llist_node tvc_completion_list;
  39. };
  40. struct tcm_vhost_nexus {
  41. /* Pointer to TCM session for I_T Nexus */
  42. struct se_session *tvn_se_sess;
  43. };
  44. struct tcm_vhost_nacl {
  45. /* Binary World Wide unique Port Name for Vhost Initiator port */
  46. u64 iport_wwpn;
  47. /* ASCII formatted WWPN for Sas Initiator port */
  48. char iport_name[TCM_VHOST_NAMELEN];
  49. /* Returned by tcm_vhost_make_nodeacl() */
  50. struct se_node_acl se_node_acl;
  51. };
  52. struct vhost_scsi;
  53. struct tcm_vhost_tpg {
  54. /* Vhost port target portal group tag for TCM */
  55. u16 tport_tpgt;
  56. /* Used to track number of TPG Port/Lun Links wrt to explict I_T Nexus shutdown */
  57. int tv_tpg_port_count;
  58. /* Used for vhost_scsi device reference to tpg_nexus, protected by tv_tpg_mutex */
  59. int tv_tpg_vhost_count;
  60. /* list for tcm_vhost_list */
  61. struct list_head tv_tpg_list;
  62. /* Used to protect access for tpg_nexus */
  63. struct mutex tv_tpg_mutex;
  64. /* Pointer to the TCM VHost I_T Nexus for this TPG endpoint */
  65. struct tcm_vhost_nexus *tpg_nexus;
  66. /* Pointer back to tcm_vhost_tport */
  67. struct tcm_vhost_tport *tport;
  68. /* Returned by tcm_vhost_make_tpg() */
  69. struct se_portal_group se_tpg;
  70. /* Pointer back to vhost_scsi, protected by tv_tpg_mutex */
  71. struct vhost_scsi *vhost_scsi;
  72. };
  73. struct tcm_vhost_tport {
  74. /* SCSI protocol the tport is providing */
  75. u8 tport_proto_id;
  76. /* Binary World Wide unique Port Name for Vhost Target port */
  77. u64 tport_wwpn;
  78. /* ASCII formatted WWPN for Vhost Target port */
  79. char tport_name[TCM_VHOST_NAMELEN];
  80. /* Returned by tcm_vhost_make_tport() */
  81. struct se_wwn tport_wwn;
  82. };
  83. struct tcm_vhost_evt {
  84. /* event to be sent to guest */
  85. struct virtio_scsi_event event;
  86. /* event list, serviced from vhost worker thread */
  87. struct llist_node list;
  88. };
  89. /*
  90. * As per request from MST, keep TCM_VHOST related ioctl defines out of
  91. * linux/vhost.h (user-space) for now..
  92. */
  93. #include <linux/vhost.h>
  94. /*
  95. * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
  96. *
  97. * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
  98. * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
  99. * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
  100. * All the targets under vhost_wwpn can be seen and used by guset.
  101. */
  102. #define VHOST_SCSI_ABI_VERSION 1
  103. struct vhost_scsi_target {
  104. int abi_version;
  105. char vhost_wwpn[TRANSPORT_IQN_LEN];
  106. unsigned short vhost_tpgt;
  107. unsigned short reserved;
  108. };
  109. /* VHOST_SCSI specific defines */
  110. #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
  111. #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
  112. /* Changing this breaks userspace. */
  113. #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)