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