virtio_scsi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * This header is BSD licensed so anyone can use the definitions to implement
  3. * compatible drivers/servers.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. */
  26. #ifndef _LINUX_VIRTIO_SCSI_H
  27. #define _LINUX_VIRTIO_SCSI_H
  28. #include <linux/virtio_types.h>
  29. /* Default values of the CDB and sense data size configuration fields */
  30. #define VIRTIO_SCSI_CDB_DEFAULT_SIZE 32
  31. #define VIRTIO_SCSI_SENSE_DEFAULT_SIZE 96
  32. #ifndef VIRTIO_SCSI_CDB_SIZE
  33. #define VIRTIO_SCSI_CDB_SIZE VIRTIO_SCSI_CDB_DEFAULT_SIZE
  34. #endif
  35. #ifndef VIRTIO_SCSI_SENSE_SIZE
  36. #define VIRTIO_SCSI_SENSE_SIZE VIRTIO_SCSI_SENSE_DEFAULT_SIZE
  37. #endif
  38. /* SCSI command request, followed by data-out */
  39. struct virtio_scsi_cmd_req {
  40. __u8 lun[8]; /* Logical Unit Number */
  41. __virtio64 tag; /* Command identifier */
  42. __u8 task_attr; /* Task attribute */
  43. __u8 prio; /* SAM command priority field */
  44. __u8 crn;
  45. __u8 cdb[VIRTIO_SCSI_CDB_SIZE];
  46. } __attribute__((packed));
  47. /* SCSI command request, followed by protection information */
  48. struct virtio_scsi_cmd_req_pi {
  49. __u8 lun[8]; /* Logical Unit Number */
  50. __virtio64 tag; /* Command identifier */
  51. __u8 task_attr; /* Task attribute */
  52. __u8 prio; /* SAM command priority field */
  53. __u8 crn;
  54. __virtio32 pi_bytesout; /* DataOUT PI Number of bytes */
  55. __virtio32 pi_bytesin; /* DataIN PI Number of bytes */
  56. __u8 cdb[VIRTIO_SCSI_CDB_SIZE];
  57. } __attribute__((packed));
  58. /* Response, followed by sense data and data-in */
  59. struct virtio_scsi_cmd_resp {
  60. __virtio32 sense_len; /* Sense data length */
  61. __virtio32 resid; /* Residual bytes in data buffer */
  62. __virtio16 status_qualifier; /* Status qualifier */
  63. __u8 status; /* Command completion status */
  64. __u8 response; /* Response values */
  65. __u8 sense[VIRTIO_SCSI_SENSE_SIZE];
  66. } __attribute__((packed));
  67. /* Task Management Request */
  68. struct virtio_scsi_ctrl_tmf_req {
  69. __virtio32 type;
  70. __virtio32 subtype;
  71. __u8 lun[8];
  72. __virtio64 tag;
  73. } __attribute__((packed));
  74. struct virtio_scsi_ctrl_tmf_resp {
  75. __u8 response;
  76. } __attribute__((packed));
  77. /* Asynchronous notification query/subscription */
  78. struct virtio_scsi_ctrl_an_req {
  79. __virtio32 type;
  80. __u8 lun[8];
  81. __virtio32 event_requested;
  82. } __attribute__((packed));
  83. struct virtio_scsi_ctrl_an_resp {
  84. __virtio32 event_actual;
  85. __u8 response;
  86. } __attribute__((packed));
  87. struct virtio_scsi_event {
  88. __virtio32 event;
  89. __u8 lun[8];
  90. __virtio32 reason;
  91. } __attribute__((packed));
  92. struct virtio_scsi_config {
  93. __u32 num_queues;
  94. __u32 seg_max;
  95. __u32 max_sectors;
  96. __u32 cmd_per_lun;
  97. __u32 event_info_size;
  98. __u32 sense_size;
  99. __u32 cdb_size;
  100. __u16 max_channel;
  101. __u16 max_target;
  102. __u32 max_lun;
  103. } __attribute__((packed));
  104. /* Feature Bits */
  105. #define VIRTIO_SCSI_F_INOUT 0
  106. #define VIRTIO_SCSI_F_HOTPLUG 1
  107. #define VIRTIO_SCSI_F_CHANGE 2
  108. #define VIRTIO_SCSI_F_T10_PI 3
  109. /* Response codes */
  110. #define VIRTIO_SCSI_S_OK 0
  111. #define VIRTIO_SCSI_S_OVERRUN 1
  112. #define VIRTIO_SCSI_S_ABORTED 2
  113. #define VIRTIO_SCSI_S_BAD_TARGET 3
  114. #define VIRTIO_SCSI_S_RESET 4
  115. #define VIRTIO_SCSI_S_BUSY 5
  116. #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
  117. #define VIRTIO_SCSI_S_TARGET_FAILURE 7
  118. #define VIRTIO_SCSI_S_NEXUS_FAILURE 8
  119. #define VIRTIO_SCSI_S_FAILURE 9
  120. #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
  121. #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
  122. #define VIRTIO_SCSI_S_INCORRECT_LUN 12
  123. /* Controlq type codes. */
  124. #define VIRTIO_SCSI_T_TMF 0
  125. #define VIRTIO_SCSI_T_AN_QUERY 1
  126. #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
  127. /* Valid TMF subtypes. */
  128. #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
  129. #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
  130. #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
  131. #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
  132. #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
  133. #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
  134. #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
  135. #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
  136. /* Events. */
  137. #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
  138. #define VIRTIO_SCSI_T_NO_EVENT 0
  139. #define VIRTIO_SCSI_T_TRANSPORT_RESET 1
  140. #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
  141. #define VIRTIO_SCSI_T_PARAM_CHANGE 3
  142. /* Reasons of transport reset event */
  143. #define VIRTIO_SCSI_EVT_RESET_HARD 0
  144. #define VIRTIO_SCSI_EVT_RESET_RESCAN 1
  145. #define VIRTIO_SCSI_EVT_RESET_REMOVED 2
  146. #define VIRTIO_SCSI_S_SIMPLE 0
  147. #define VIRTIO_SCSI_S_ORDERED 1
  148. #define VIRTIO_SCSI_S_HEAD 2
  149. #define VIRTIO_SCSI_S_ACA 3
  150. #endif /* _LINUX_VIRTIO_SCSI_H */