target_core_user.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __TARGET_CORE_USER_H
  2. #define __TARGET_CORE_USER_H
  3. /* This header will be used by application too */
  4. #include <linux/types.h>
  5. #include <linux/uio.h>
  6. #define TCMU_VERSION "2.0"
  7. /*
  8. * Ring Design
  9. * -----------
  10. *
  11. * The mmaped area is divided into three parts:
  12. * 1) The mailbox (struct tcmu_mailbox, below)
  13. * 2) The command ring
  14. * 3) Everything beyond the command ring (data)
  15. *
  16. * The mailbox tells userspace the offset of the command ring from the
  17. * start of the shared memory region, and how big the command ring is.
  18. *
  19. * The kernel passes SCSI commands to userspace by putting a struct
  20. * tcmu_cmd_entry in the ring, updating mailbox->cmd_head, and poking
  21. * userspace via uio's interrupt mechanism.
  22. *
  23. * tcmu_cmd_entry contains a header. If the header type is PAD,
  24. * userspace should skip hdr->length bytes (mod cmdr_size) to find the
  25. * next cmd_entry.
  26. *
  27. * Otherwise, the entry will contain offsets into the mmaped area that
  28. * contain the cdb and data buffers -- the latter accessible via the
  29. * iov array. iov addresses are also offsets into the shared area.
  30. *
  31. * When userspace is completed handling the command, set
  32. * entry->rsp.scsi_status, fill in rsp.sense_buffer if appropriate,
  33. * and also set mailbox->cmd_tail equal to the old cmd_tail plus
  34. * hdr->length, mod cmdr_size. If cmd_tail doesn't equal cmd_head, it
  35. * should process the next packet the same way, and so on.
  36. */
  37. #define TCMU_MAILBOX_VERSION 2
  38. #define ALIGN_SIZE 64 /* Should be enough for most CPUs */
  39. struct tcmu_mailbox {
  40. __u16 version;
  41. __u16 flags;
  42. __u32 cmdr_off;
  43. __u32 cmdr_size;
  44. __u32 cmd_head;
  45. /* Updated by user. On its own cacheline */
  46. __u32 cmd_tail __attribute__((__aligned__(ALIGN_SIZE)));
  47. } __packed;
  48. enum tcmu_opcode {
  49. TCMU_OP_PAD = 0,
  50. TCMU_OP_CMD,
  51. };
  52. /*
  53. * Only a few opcodes, and length is 8-byte aligned, so use low bits for opcode.
  54. */
  55. struct tcmu_cmd_entry_hdr {
  56. __u32 len_op;
  57. __u16 cmd_id;
  58. __u8 kflags;
  59. #define TCMU_UFLAG_UNKNOWN_OP 0x1
  60. __u8 uflags;
  61. } __packed;
  62. #define TCMU_OP_MASK 0x7
  63. static inline enum tcmu_opcode tcmu_hdr_get_op(__u32 len_op)
  64. {
  65. return len_op & TCMU_OP_MASK;
  66. }
  67. static inline void tcmu_hdr_set_op(__u32 *len_op, enum tcmu_opcode op)
  68. {
  69. *len_op &= ~TCMU_OP_MASK;
  70. *len_op |= (op & TCMU_OP_MASK);
  71. }
  72. static inline __u32 tcmu_hdr_get_len(__u32 len_op)
  73. {
  74. return len_op & ~TCMU_OP_MASK;
  75. }
  76. static inline void tcmu_hdr_set_len(__u32 *len_op, __u32 len)
  77. {
  78. *len_op &= TCMU_OP_MASK;
  79. *len_op |= len;
  80. }
  81. /* Currently the same as SCSI_SENSE_BUFFERSIZE */
  82. #define TCMU_SENSE_BUFFERSIZE 96
  83. struct tcmu_cmd_entry {
  84. struct tcmu_cmd_entry_hdr hdr;
  85. union {
  86. struct {
  87. uint32_t iov_cnt;
  88. uint32_t iov_bidi_cnt;
  89. uint32_t iov_dif_cnt;
  90. uint64_t cdb_off;
  91. uint64_t __pad1;
  92. uint64_t __pad2;
  93. struct iovec iov[0];
  94. } req;
  95. struct {
  96. uint8_t scsi_status;
  97. uint8_t __pad1;
  98. uint16_t __pad2;
  99. uint32_t __pad3;
  100. char sense_buffer[TCMU_SENSE_BUFFERSIZE];
  101. } rsp;
  102. };
  103. } __packed;
  104. #define TCMU_OP_ALIGN_SIZE sizeof(uint64_t)
  105. enum tcmu_genl_cmd {
  106. TCMU_CMD_UNSPEC,
  107. TCMU_CMD_ADDED_DEVICE,
  108. TCMU_CMD_REMOVED_DEVICE,
  109. __TCMU_CMD_MAX,
  110. };
  111. #define TCMU_CMD_MAX (__TCMU_CMD_MAX - 1)
  112. enum tcmu_genl_attr {
  113. TCMU_ATTR_UNSPEC,
  114. TCMU_ATTR_DEVICE,
  115. TCMU_ATTR_MINOR,
  116. __TCMU_ATTR_MAX,
  117. };
  118. #define TCMU_ATTR_MAX (__TCMU_ATTR_MAX - 1)
  119. #endif