vscsiif.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /******************************************************************************
  2. * vscsiif.h
  3. *
  4. * Based on the blkif.h code.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright(c) FUJITSU Limited 2008.
  25. */
  26. #ifndef __XEN__PUBLIC_IO_SCSI_H__
  27. #define __XEN__PUBLIC_IO_SCSI_H__
  28. #include "ring.h"
  29. #include "../grant_table.h"
  30. /*
  31. * Feature and Parameter Negotiation
  32. * =================================
  33. * The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to
  34. * communicate capabilities and to negotiate operating parameters. This
  35. * section enumerates these nodes which reside in the respective front and
  36. * backend portions of the XenStore, following the XenBus convention.
  37. *
  38. * Any specified default value is in effect if the corresponding XenBus node
  39. * is not present in the XenStore.
  40. *
  41. * XenStore nodes in sections marked "PRIVATE" are solely for use by the
  42. * driver side whose XenBus tree contains them.
  43. *
  44. *****************************************************************************
  45. * Backend XenBus Nodes
  46. *****************************************************************************
  47. *
  48. *------------------ Backend Device Identification (PRIVATE) ------------------
  49. *
  50. * p-devname
  51. * Values: string
  52. *
  53. * A free string used to identify the physical device (e.g. a disk name).
  54. *
  55. * p-dev
  56. * Values: string
  57. *
  58. * A string specifying the backend device: either a 4-tuple "h:c:t:l"
  59. * (host, controller, target, lun, all integers), or a WWN (e.g.
  60. * "naa.60014054ac780582").
  61. *
  62. * v-dev
  63. * Values: string
  64. *
  65. * A string specifying the frontend device in form of a 4-tuple "h:c:t:l"
  66. * (host, controller, target, lun, all integers).
  67. *
  68. *--------------------------------- Features ---------------------------------
  69. *
  70. * feature-sg-grant
  71. * Values: unsigned [VSCSIIF_SG_TABLESIZE...65535]
  72. * Default Value: 0
  73. *
  74. * Specifies the maximum number of scatter/gather elements in grant pages
  75. * supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE
  76. * SG elements specified directly in the request.
  77. *
  78. *****************************************************************************
  79. * Frontend XenBus Nodes
  80. *****************************************************************************
  81. *
  82. *----------------------- Request Transport Parameters -----------------------
  83. *
  84. * event-channel
  85. * Values: unsigned
  86. *
  87. * The identifier of the Xen event channel used to signal activity
  88. * in the ring buffer.
  89. *
  90. * ring-ref
  91. * Values: unsigned
  92. *
  93. * The Xen grant reference granting permission for the backend to map
  94. * the sole page in a single page sized ring buffer.
  95. *
  96. * protocol
  97. * Values: string (XEN_IO_PROTO_ABI_*)
  98. * Default Value: XEN_IO_PROTO_ABI_NATIVE
  99. *
  100. * The machine ABI rules governing the format of all ring request and
  101. * response structures.
  102. */
  103. /* Requests from the frontend to the backend */
  104. /*
  105. * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.
  106. * The target is specified via channel, id and lun.
  107. *
  108. * The operation to be performed is specified via a CDB in cmnd[], the length
  109. * of the CDB is in cmd_len. sc_data_direction specifies the direction of data
  110. * (to the device, from the device, or none at all).
  111. *
  112. * If data is to be transferred to or from the device the buffer(s) in the
  113. * guest memory is/are specified via one or multiple scsiif_request_segment
  114. * descriptors each specifying a memory page via a grant_ref_t, a offset into
  115. * the page and the length of the area in that page. All scsiif_request_segment
  116. * areas concatenated form the resulting data buffer used by the operation.
  117. * If the number of scsiif_request_segment areas is not too large (less than
  118. * or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the
  119. * seg[] array and the number of valid scsiif_request_segment elements is to be
  120. * set in nr_segments.
  121. *
  122. * If "feature-sg-grant" in the Xenstore is set it is possible to specify more
  123. * than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection.
  124. * The maximum number of allowed scsiif_request_segment elements is the value
  125. * of the "feature-sg-grant" entry from Xenstore. When using indirection the
  126. * seg[] array doesn't contain specifications of the data buffers, but
  127. * references to scsiif_request_segment arrays, which in turn reference the
  128. * data buffers. While nr_segments holds the number of populated seg[] entries
  129. * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment
  130. * elements referencing the target data buffers is calculated from the lengths
  131. * of the seg[] elements (the sum of all valid seg[].length divided by the
  132. * size of one scsiif_request_segment structure).
  133. */
  134. #define VSCSIIF_ACT_SCSI_CDB 1
  135. /*
  136. * Request abort of a running operation for the specified target given by
  137. * channel, id, lun and the operation's rqid in ref_rqid.
  138. */
  139. #define VSCSIIF_ACT_SCSI_ABORT 2
  140. /*
  141. * Request a device reset of the specified target (channel and id).
  142. */
  143. #define VSCSIIF_ACT_SCSI_RESET 3
  144. /*
  145. * Preset scatter/gather elements for a following request. Deprecated.
  146. * Keeping the define only to avoid usage of the value "4" for other actions.
  147. */
  148. #define VSCSIIF_ACT_SCSI_SG_PRESET 4
  149. /*
  150. * Maximum scatter/gather segments per request.
  151. *
  152. * Considering balance between allocating at least 16 "vscsiif_request"
  153. * structures on one page (4096 bytes) and the number of scatter/gather
  154. * elements needed, we decided to use 26 as a magic number.
  155. *
  156. * If "feature-sg-grant" is set, more scatter/gather elements can be specified
  157. * by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages.
  158. * In this case the vscsiif_request seg elements don't contain references to
  159. * the user data, but to the SG elements referencing the user data.
  160. */
  161. #define VSCSIIF_SG_TABLESIZE 26
  162. /*
  163. * based on Linux kernel 2.6.18, still valid
  164. * Changing these values requires support of multiple protocols via the rings
  165. * as "old clients" will blindly use these values and the resulting structure
  166. * sizes.
  167. */
  168. #define VSCSIIF_MAX_COMMAND_SIZE 16
  169. #define VSCSIIF_SENSE_BUFFERSIZE 96
  170. struct scsiif_request_segment {
  171. grant_ref_t gref;
  172. uint16_t offset;
  173. uint16_t length;
  174. };
  175. #define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segment))
  176. /* Size of one request is 252 bytes */
  177. struct vscsiif_request {
  178. uint16_t rqid; /* private guest value, echoed in resp */
  179. uint8_t act; /* command between backend and frontend */
  180. uint8_t cmd_len; /* valid CDB bytes */
  181. uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */
  182. uint16_t timeout_per_command; /* deprecated */
  183. uint16_t channel, id, lun; /* (virtual) device specification */
  184. uint16_t ref_rqid; /* command abort reference */
  185. uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1)
  186. DMA_FROM_DEVICE(2)
  187. DMA_NONE(3) requests */
  188. uint8_t nr_segments; /* Number of pieces of scatter-gather */
  189. /*
  190. * flag in nr_segments: SG elements via grant page
  191. *
  192. * If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number
  193. * of grant pages containing SG elements. Usable if "feature-sg-grant" set.
  194. */
  195. #define VSCSIIF_SG_GRANT 0x80
  196. struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE];
  197. uint32_t reserved[3];
  198. };
  199. /* Size of one response is 252 bytes */
  200. struct vscsiif_response {
  201. uint16_t rqid; /* identifies request */
  202. uint8_t padding;
  203. uint8_t sense_len;
  204. uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
  205. int32_t rslt;
  206. uint32_t residual_len; /* request bufflen -
  207. return the value from physical device */
  208. uint32_t reserved[36];
  209. };
  210. DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
  211. #endif /*__XEN__PUBLIC_IO_SCSI_H__*/