1 1.1 cherry /****************************************************************************** 2 1.1 cherry * vscsiif.h 3 1.1 cherry * 4 1.1 cherry * Based on the blkif.h code. 5 1.1 cherry * 6 1.1 cherry * Permission is hereby granted, free of charge, to any person obtaining a copy 7 1.1 cherry * of this software and associated documentation files (the "Software"), to 8 1.1 cherry * deal in the Software without restriction, including without limitation the 9 1.1 cherry * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 1.1 cherry * sell copies of the Software, and to permit persons to whom the Software is 11 1.1 cherry * furnished to do so, subject to the following conditions: 12 1.1 cherry * 13 1.1 cherry * The above copyright notice and this permission notice shall be included in 14 1.1 cherry * all copies or substantial portions of the Software. 15 1.1 cherry * 16 1.1 cherry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 cherry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 cherry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 1.1 cherry * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 1.1 cherry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 1.1 cherry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 1.1 cherry * DEALINGS IN THE SOFTWARE. 23 1.1 cherry * 24 1.1 cherry * Copyright(c) FUJITSU Limited 2008. 25 1.1 cherry */ 26 1.1 cherry 27 1.1 cherry #ifndef __XEN__PUBLIC_IO_SCSI_H__ 28 1.1 cherry #define __XEN__PUBLIC_IO_SCSI_H__ 29 1.1 cherry 30 1.1 cherry #include "ring.h" 31 1.1 cherry #include "../grant_table.h" 32 1.1 cherry 33 1.1 cherry /* 34 1.1 cherry * Feature and Parameter Negotiation 35 1.1 cherry * ================================= 36 1.1 cherry * The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to 37 1.1 cherry * communicate capabilities and to negotiate operating parameters. This 38 1.1 cherry * section enumerates these nodes which reside in the respective front and 39 1.1 cherry * backend portions of the XenStore, following the XenBus convention. 40 1.1 cherry * 41 1.1 cherry * Any specified default value is in effect if the corresponding XenBus node 42 1.1 cherry * is not present in the XenStore. 43 1.1 cherry * 44 1.1 cherry * XenStore nodes in sections marked "PRIVATE" are solely for use by the 45 1.1 cherry * driver side whose XenBus tree contains them. 46 1.1 cherry * 47 1.1 cherry ***************************************************************************** 48 1.1 cherry * Backend XenBus Nodes 49 1.1 cherry ***************************************************************************** 50 1.1 cherry * 51 1.1 cherry *------------------ Backend Device Identification (PRIVATE) ------------------ 52 1.1 cherry * 53 1.1 cherry * p-devname 54 1.1 cherry * Values: string 55 1.1 cherry * 56 1.1 cherry * A free string used to identify the physical device (e.g. a disk name). 57 1.1 cherry * 58 1.1 cherry * p-dev 59 1.1 cherry * Values: string 60 1.1 cherry * 61 1.1 cherry * A string specifying the backend device: either a 4-tuple "h:c:t:l" 62 1.1 cherry * (host, controller, target, lun, all integers), or a WWN (e.g. 63 1.1 cherry * "naa.60014054ac780582:0"). 64 1.1 cherry * 65 1.1 cherry * v-dev 66 1.1 cherry * Values: string 67 1.1 cherry * 68 1.1 cherry * A string specifying the frontend device in form of a 4-tuple "h:c:t:l" 69 1.1 cherry * (host, controller, target, lun, all integers). 70 1.1 cherry * 71 1.1 cherry *--------------------------------- Features --------------------------------- 72 1.1 cherry * 73 1.1 cherry * feature-sg-grant 74 1.1 cherry * Values: unsigned [VSCSIIF_SG_TABLESIZE...65535] 75 1.1 cherry * Default Value: 0 76 1.1 cherry * 77 1.1 cherry * Specifies the maximum number of scatter/gather elements in grant pages 78 1.1 cherry * supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE 79 1.1 cherry * SG elements specified directly in the request. 80 1.1 cherry * 81 1.1 cherry ***************************************************************************** 82 1.1 cherry * Frontend XenBus Nodes 83 1.1 cherry ***************************************************************************** 84 1.1 cherry * 85 1.1 cherry *----------------------- Request Transport Parameters ----------------------- 86 1.1 cherry * 87 1.1 cherry * event-channel 88 1.1 cherry * Values: unsigned 89 1.1 cherry * 90 1.1 cherry * The identifier of the Xen event channel used to signal activity 91 1.1 cherry * in the ring buffer. 92 1.1 cherry * 93 1.1 cherry * ring-ref 94 1.1 cherry * Values: unsigned 95 1.1 cherry * 96 1.1 cherry * The Xen grant reference granting permission for the backend to map 97 1.1 cherry * the sole page in a single page sized ring buffer. 98 1.1 cherry * 99 1.1 cherry * protocol 100 1.1 cherry * Values: string (XEN_IO_PROTO_ABI_*) 101 1.1 cherry * Default Value: XEN_IO_PROTO_ABI_NATIVE 102 1.1 cherry * 103 1.1 cherry * The machine ABI rules governing the format of all ring request and 104 1.1 cherry * response structures. 105 1.1 cherry */ 106 1.1 cherry 107 1.1 cherry /* 108 1.1 cherry * Xenstore format in practice 109 1.1 cherry * =========================== 110 1.1 cherry * 111 1.1 cherry * The backend driver uses a single_host:many_devices notation to manage domU 112 1.1 cherry * devices. Everything is stored in /local/domain/<backend_domid>/backend/vscsi/. 113 1.1 cherry * The xenstore layout looks like this (dom0 is assumed to be the backend_domid): 114 1.1 cherry * 115 1.1 cherry * <domid>/<vhost>/feature-host = "0" 116 1.1 cherry * <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0" 117 1.1 cherry * <domid>/<vhost>/frontend-id = "<domid>" 118 1.1 cherry * <domid>/<vhost>/online = "1" 119 1.1 cherry * <domid>/<vhost>/state = "4" 120 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1" or "naa.wwn:lun" 121 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/state = "4" 122 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0" 123 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2" 124 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/state = "4" 125 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0" 126 1.1 cherry * 127 1.1 cherry * The frontend driver maintains its state in 128 1.1 cherry * /local/domain/<domid>/device/vscsi/. 129 1.1 cherry * 130 1.1 cherry * <vhost>/backend = "/local/domain/0/backend/vscsi/<domid>/<vhost>" 131 1.1 cherry * <vhost>/backend-id = "0" 132 1.1 cherry * <vhost>/event-channel = "20" 133 1.1 cherry * <vhost>/ring-ref = "43" 134 1.1 cherry * <vhost>/state = "4" 135 1.1 cherry * <vhost>/vscsi-devs/dev-0/state = "4" 136 1.1 cherry * <vhost>/vscsi-devs/dev-1/state = "4" 137 1.1 cherry * 138 1.1 cherry * In addition to the entries for backend and frontend these flags are stored 139 1.1 cherry * for the toolstack: 140 1.1 cherry * 141 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/p-devname = "/dev/$device" 142 1.1 cherry * <domid>/<vhost>/libxl_ctrl_index = "0" 143 1.1 cherry * 144 1.1 cherry * 145 1.1 cherry * Backend/frontend protocol 146 1.1 cherry * ========================= 147 1.1 cherry * 148 1.1 cherry * To create a vhost along with a device: 149 1.1 cherry * <domid>/<vhost>/feature-host = "0" 150 1.1 cherry * <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0" 151 1.1 cherry * <domid>/<vhost>/frontend-id = "<domid>" 152 1.1 cherry * <domid>/<vhost>/online = "1" 153 1.1 cherry * <domid>/<vhost>/state = "1" 154 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1" 155 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/state = "1" 156 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0" 157 1.1 cherry * Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-0/state become 4 158 1.1 cherry * 159 1.1 cherry * To add another device to a vhost: 160 1.1 cherry * <domid>/<vhost>/state = "7" 161 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2" 162 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/state = "1" 163 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0" 164 1.1 cherry * Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-1/state become 4 165 1.1 cherry * 166 1.1 cherry * To remove a device from a vhost: 167 1.1 cherry * <domid>/<vhost>/state = "7" 168 1.1 cherry * <domid>/<vhost>/vscsi-devs/dev-1/state = "5" 169 1.1 cherry * Wait for <domid>/<vhost>/state to become 4 170 1.1 cherry * Wait for <domid>/<vhost>/vscsi-devs/dev-1/state become 6 171 1.1 cherry * Remove <domid>/<vhost>/vscsi-devs/dev-1/{state,p-dev,v-dev,p-devname} 172 1.1 cherry * Remove <domid>/<vhost>/vscsi-devs/dev-1/ 173 1.1 cherry * 174 1.1 cherry */ 175 1.1 cherry 176 1.1 cherry /* Requests from the frontend to the backend */ 177 1.1 cherry 178 1.1 cherry /* 179 1.1 cherry * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd. 180 1.1 cherry * The target is specified via channel, id and lun. 181 1.1 cherry * 182 1.1 cherry * The operation to be performed is specified via a CDB in cmnd[], the length 183 1.1 cherry * of the CDB is in cmd_len. sc_data_direction specifies the direction of data 184 1.1 cherry * (to the device, from the device, or none at all). 185 1.1 cherry * 186 1.1 cherry * If data is to be transferred to or from the device the buffer(s) in the 187 1.1 cherry * guest memory is/are specified via one or multiple scsiif_request_segment 188 1.1 cherry * descriptors each specifying a memory page via a grant_ref_t, a offset into 189 1.1 cherry * the page and the length of the area in that page. All scsiif_request_segment 190 1.1 cherry * areas concatenated form the resulting data buffer used by the operation. 191 1.1 cherry * If the number of scsiif_request_segment areas is not too large (less than 192 1.1 cherry * or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the 193 1.1 cherry * seg[] array and the number of valid scsiif_request_segment elements is to be 194 1.1 cherry * set in nr_segments. 195 1.1 cherry * 196 1.1 cherry * If "feature-sg-grant" in the Xenstore is set it is possible to specify more 197 1.1 cherry * than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection. 198 1.1 cherry * The maximum number of allowed scsiif_request_segment elements is the value 199 1.1 cherry * of the "feature-sg-grant" entry from Xenstore. When using indirection the 200 1.1 cherry * seg[] array doesn't contain specifications of the data buffers, but 201 1.1 cherry * references to scsiif_request_segment arrays, which in turn reference the 202 1.1 cherry * data buffers. While nr_segments holds the number of populated seg[] entries 203 1.1 cherry * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment 204 1.1 cherry * elements referencing the target data buffers is calculated from the lengths 205 1.1 cherry * of the seg[] elements (the sum of all valid seg[].length divided by the 206 1.1 cherry * size of one scsiif_request_segment structure). The frontend may use a mix of 207 1.1 cherry * direct and indirect requests. 208 1.1 cherry */ 209 1.1 cherry #define VSCSIIF_ACT_SCSI_CDB 1 210 1.1 cherry 211 1.1 cherry /* 212 1.1 cherry * Request abort of a running operation for the specified target given by 213 1.1 cherry * channel, id, lun and the operation's rqid in ref_rqid. 214 1.1 cherry */ 215 1.1 cherry #define VSCSIIF_ACT_SCSI_ABORT 2 216 1.1 cherry 217 1.1 cherry /* 218 1.1 cherry * Request a device reset of the specified target (channel and id). 219 1.1 cherry */ 220 1.1 cherry #define VSCSIIF_ACT_SCSI_RESET 3 221 1.1 cherry 222 1.1 cherry /* 223 1.1 cherry * Preset scatter/gather elements for a following request. Deprecated. 224 1.1 cherry * Keeping the define only to avoid usage of the value "4" for other actions. 225 1.1 cherry */ 226 1.1 cherry #define VSCSIIF_ACT_SCSI_SG_PRESET 4 227 1.1 cherry 228 1.1 cherry /* 229 1.1 cherry * Maximum scatter/gather segments per request. 230 1.1 cherry * 231 1.1 cherry * Considering balance between allocating at least 16 "vscsiif_request" 232 1.1 cherry * structures on one page (4096 bytes) and the number of scatter/gather 233 1.1 cherry * elements needed, we decided to use 26 as a magic number. 234 1.1 cherry * 235 1.1 cherry * If "feature-sg-grant" is set, more scatter/gather elements can be specified 236 1.1 cherry * by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages. 237 1.1 cherry * In this case the vscsiif_request seg elements don't contain references to 238 1.1 cherry * the user data, but to the SG elements referencing the user data. 239 1.1 cherry */ 240 1.1 cherry #define VSCSIIF_SG_TABLESIZE 26 241 1.1 cherry 242 1.1 cherry /* 243 1.1 cherry * based on Linux kernel 2.6.18, still valid 244 1.1 cherry * 245 1.1 cherry * Changing these values requires support of multiple protocols via the rings 246 1.1 cherry * as "old clients" will blindly use these values and the resulting structure 247 1.1 cherry * sizes. 248 1.1 cherry */ 249 1.1 cherry #define VSCSIIF_MAX_COMMAND_SIZE 16 250 1.1 cherry #define VSCSIIF_SENSE_BUFFERSIZE 96 251 1.1 cherry #define VSCSIIF_PAGE_SIZE 4096 252 1.1 cherry 253 1.1 cherry struct scsiif_request_segment { 254 1.1 cherry grant_ref_t gref; 255 1.1 cherry uint16_t offset; 256 1.1 cherry uint16_t length; 257 1.1 cherry }; 258 1.1 cherry typedef struct scsiif_request_segment vscsiif_segment_t; 259 1.1 cherry 260 1.1 cherry #define VSCSIIF_SG_PER_PAGE (VSCSIIF_PAGE_SIZE / sizeof(struct scsiif_request_segment)) 261 1.1 cherry 262 1.1 cherry /* Size of one request is 252 bytes */ 263 1.1 cherry struct vscsiif_request { 264 1.1 cherry uint16_t rqid; /* private guest value, echoed in resp */ 265 1.1 cherry uint8_t act; /* command between backend and frontend */ 266 1.1 cherry uint8_t cmd_len; /* valid CDB bytes */ 267 1.1 cherry 268 1.1 cherry uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */ 269 1.1 cherry uint16_t timeout_per_command; /* deprecated: timeout in secs, 0=default */ 270 1.1 cherry uint16_t channel, id, lun; /* (virtual) device specification */ 271 1.1 cherry uint16_t ref_rqid; /* command abort reference */ 272 1.1 cherry uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1) 273 1.1 cherry DMA_FROM_DEVICE(2) 274 1.1 cherry DMA_NONE(3) requests */ 275 1.1 cherry uint8_t nr_segments; /* Number of pieces of scatter-gather */ 276 1.1 cherry /* 277 1.1 cherry * flag in nr_segments: SG elements via grant page 278 1.1 cherry * 279 1.1 cherry * If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number 280 1.1 cherry * of grant pages containing SG elements. Usable if "feature-sg-grant" set. 281 1.1 cherry */ 282 1.1 cherry #define VSCSIIF_SG_GRANT 0x80 283 1.1 cherry 284 1.1 cherry vscsiif_segment_t seg[VSCSIIF_SG_TABLESIZE]; 285 1.1 cherry uint32_t reserved[3]; 286 1.1 cherry }; 287 1.1 cherry typedef struct vscsiif_request vscsiif_request_t; 288 1.1 cherry 289 1.1 cherry /* 290 1.1 cherry * The following interface is deprecated! 291 1.1 cherry */ 292 1.1 cherry #define VSCSIIF_SG_LIST_SIZE ((sizeof(vscsiif_request_t) - 4) \ 293 1.1 cherry / sizeof(vscsiif_segment_t)) 294 1.1 cherry 295 1.1 cherry struct vscsiif_sg_list { 296 1.1 cherry /* First two fields must match struct vscsiif_request! */ 297 1.1 cherry uint16_t rqid; /* private guest value, must match main req */ 298 1.1 cherry uint8_t act; /* VSCSIIF_ACT_SCSI_SG_PRESET */ 299 1.1 cherry uint8_t nr_segments; /* Number of pieces of scatter-gather */ 300 1.1 cherry vscsiif_segment_t seg[VSCSIIF_SG_LIST_SIZE]; 301 1.1 cherry }; 302 1.1 cherry typedef struct vscsiif_sg_list vscsiif_sg_list_t; 303 1.1 cherry /* End of deprecated interface */ 304 1.1 cherry 305 1.1 cherry /* Size of one response is 252 bytes */ 306 1.1 cherry struct vscsiif_response { 307 1.1 cherry uint16_t rqid; /* identifies request */ 308 1.1 cherry uint8_t act; /* deprecated: valid only if SG_PRESET supported */ 309 1.1 cherry uint8_t sense_len; 310 1.1 cherry uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE]; 311 1.1 cherry int32_t rslt; 312 1.1 cherry uint32_t residual_len; /* request bufflen - 313 1.1 cherry return the value from physical device */ 314 1.1 cherry uint32_t reserved[36]; 315 1.1 cherry }; 316 1.1 cherry typedef struct vscsiif_response vscsiif_response_t; 317 1.1 cherry 318 1.1 cherry DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response); 319 1.1 cherry 320 1.1 cherry 321 1.1 cherry #endif /*__XEN__PUBLIC_IO_SCSI_H__*/ 322 1.1 cherry /* 323 1.1 cherry * Local variables: 324 1.1 cherry * mode: C 325 1.1 cherry * c-file-style: "BSD" 326 1.1 cherry * c-basic-offset: 4 327 1.1 cherry * tab-width: 4 328 1.1 cherry * indent-tabs-mode: nil 329 1.1 cherry * End: 330 1.1 cherry */ 331