/******************************************************************************1* vscsiif.h2*3* Based on the blkif.h code.4*5* Permission is hereby granted, free of charge, to any person obtaining a copy6* of this software and associated documentation files (the "Software"), to7* deal in the Software without restriction, including without limitation the8* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or9* sell copies of the Software, and to permit persons to whom the Software is10* furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included in13* all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Copyright(c) FUJITSU Limited 2008.24*/2526#ifndef __XEN__PUBLIC_IO_SCSI_H__27#define __XEN__PUBLIC_IO_SCSI_H__2829#include "ring.h"30#include "../grant_table.h"3132/*33* Feature and Parameter Negotiation34* =================================35* The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to36* communicate capabilities and to negotiate operating parameters. This37* section enumerates these nodes which reside in the respective front and38* backend portions of the XenStore, following the XenBus convention.39*40* Any specified default value is in effect if the corresponding XenBus node41* is not present in the XenStore.42*43* XenStore nodes in sections marked "PRIVATE" are solely for use by the44* driver side whose XenBus tree contains them.45*46*****************************************************************************47* Backend XenBus Nodes48*****************************************************************************49*50*------------------ Backend Device Identification (PRIVATE) ------------------51*52* p-devname53* Values: string54*55* A free string used to identify the physical device (e.g. a disk name).56*57* p-dev58* Values: string59*60* A string specifying the backend device: either a 4-tuple "h:c:t:l"61* (host, controller, target, lun, all integers), or a WWN (e.g.62* "naa.60014054ac780582:0").63*64* v-dev65* Values: string66*67* A string specifying the frontend device in form of a 4-tuple "h:c:t:l"68* (host, controller, target, lun, all integers).69*70*--------------------------------- Features ---------------------------------71*72* feature-sg-grant73* Values: unsigned [VSCSIIF_SG_TABLESIZE...65535]74* Default Value: 075*76* Specifies the maximum number of scatter/gather elements in grant pages77* supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE78* SG elements specified directly in the request.79*80*****************************************************************************81* Frontend XenBus Nodes82*****************************************************************************83*84*----------------------- Request Transport Parameters -----------------------85*86* event-channel87* Values: unsigned88*89* The identifier of the Xen event channel used to signal activity90* in the ring buffer.91*92* ring-ref93* Values: unsigned94*95* The Xen grant reference granting permission for the backend to map96* the sole page in a single page sized ring buffer.97*98* protocol99* Values: string (XEN_IO_PROTO_ABI_*)100* Default Value: XEN_IO_PROTO_ABI_NATIVE101*102* The machine ABI rules governing the format of all ring request and103* response structures.104*/105106/*107* Xenstore format in practice108* ===========================109*110* The backend driver uses a single_host:many_devices notation to manage domU111* devices. Everything is stored in /local/domain/<backend_domid>/backend/vscsi/.112* The xenstore layout looks like this (dom0 is assumed to be the backend_domid):113*114* <domid>/<vhost>/feature-host = "0"115* <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"116* <domid>/<vhost>/frontend-id = "<domid>"117* <domid>/<vhost>/online = "1"118* <domid>/<vhost>/state = "4"119* <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1" or "naa.wwn:lun"120* <domid>/<vhost>/vscsi-devs/dev-0/state = "4"121* <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"122* <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"123* <domid>/<vhost>/vscsi-devs/dev-1/state = "4"124* <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"125*126* The frontend driver maintains its state in127* /local/domain/<domid>/device/vscsi/.128*129* <vhost>/backend = "/local/domain/0/backend/vscsi/<domid>/<vhost>"130* <vhost>/backend-id = "0"131* <vhost>/event-channel = "20"132* <vhost>/ring-ref = "43"133* <vhost>/state = "4"134* <vhost>/vscsi-devs/dev-0/state = "4"135* <vhost>/vscsi-devs/dev-1/state = "4"136*137* In addition to the entries for backend and frontend these flags are stored138* for the toolstack:139*140* <domid>/<vhost>/vscsi-devs/dev-1/p-devname = "/dev/$device"141* <domid>/<vhost>/libxl_ctrl_index = "0"142*143*144* Backend/frontend protocol145* =========================146*147* To create a vhost along with a device:148* <domid>/<vhost>/feature-host = "0"149* <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"150* <domid>/<vhost>/frontend-id = "<domid>"151* <domid>/<vhost>/online = "1"152* <domid>/<vhost>/state = "1"153* <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1"154* <domid>/<vhost>/vscsi-devs/dev-0/state = "1"155* <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"156* Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-0/state become 4157*158* To add another device to a vhost:159* <domid>/<vhost>/state = "7"160* <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"161* <domid>/<vhost>/vscsi-devs/dev-1/state = "1"162* <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"163* Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-1/state become 4164*165* To remove a device from a vhost:166* <domid>/<vhost>/state = "7"167* <domid>/<vhost>/vscsi-devs/dev-1/state = "5"168* Wait for <domid>/<vhost>/state to become 4169* Wait for <domid>/<vhost>/vscsi-devs/dev-1/state become 6170* Remove <domid>/<vhost>/vscsi-devs/dev-1/{state,p-dev,v-dev,p-devname}171* Remove <domid>/<vhost>/vscsi-devs/dev-1/172*173*/174175/* Requests from the frontend to the backend */176177/*178* Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.179* The target is specified via channel, id and lun.180*181* The operation to be performed is specified via a CDB in cmnd[], the length182* of the CDB is in cmd_len. sc_data_direction specifies the direction of data183* (to the device, from the device, or none at all).184*185* If data is to be transferred to or from the device the buffer(s) in the186* guest memory is/are specified via one or multiple scsiif_request_segment187* descriptors each specifying a memory page via a grant_ref_t, a offset into188* the page and the length of the area in that page. All scsiif_request_segment189* areas concatenated form the resulting data buffer used by the operation.190* If the number of scsiif_request_segment areas is not too large (less than191* or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the192* seg[] array and the number of valid scsiif_request_segment elements is to be193* set in nr_segments.194*195* If "feature-sg-grant" in the Xenstore is set it is possible to specify more196* than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection.197* The maximum number of allowed scsiif_request_segment elements is the value198* of the "feature-sg-grant" entry from Xenstore. When using indirection the199* seg[] array doesn't contain specifications of the data buffers, but200* references to scsiif_request_segment arrays, which in turn reference the201* data buffers. While nr_segments holds the number of populated seg[] entries202* (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment203* elements referencing the target data buffers is calculated from the lengths204* of the seg[] elements (the sum of all valid seg[].length divided by the205* size of one scsiif_request_segment structure). The frontend may use a mix of206* direct and indirect requests.207*/208#define VSCSIIF_ACT_SCSI_CDB 1209210/*211* Request abort of a running operation for the specified target given by212* channel, id, lun and the operation's rqid in ref_rqid.213*/214#define VSCSIIF_ACT_SCSI_ABORT 2215216/*217* Request a device reset of the specified target (channel and id).218*/219#define VSCSIIF_ACT_SCSI_RESET 3220221/*222* Preset scatter/gather elements for a following request. Deprecated.223* Keeping the define only to avoid usage of the value "4" for other actions.224*/225#define VSCSIIF_ACT_SCSI_SG_PRESET 4226227/*228* Maximum scatter/gather segments per request.229*230* Considering balance between allocating at least 16 "vscsiif_request"231* structures on one page (4096 bytes) and the number of scatter/gather232* elements needed, we decided to use 26 as a magic number.233*234* If "feature-sg-grant" is set, more scatter/gather elements can be specified235* by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages.236* In this case the vscsiif_request seg elements don't contain references to237* the user data, but to the SG elements referencing the user data.238*/239#define VSCSIIF_SG_TABLESIZE 26240241/*242* based on Linux kernel 2.6.18, still valid243*244* Changing these values requires support of multiple protocols via the rings245* as "old clients" will blindly use these values and the resulting structure246* sizes.247*/248#define VSCSIIF_MAX_COMMAND_SIZE 16249#define VSCSIIF_SENSE_BUFFERSIZE 96250#define VSCSIIF_PAGE_SIZE 4096251252struct scsiif_request_segment {253grant_ref_t gref;254uint16_t offset;255uint16_t length;256};257typedef struct scsiif_request_segment vscsiif_segment_t;258259#define VSCSIIF_SG_PER_PAGE (VSCSIIF_PAGE_SIZE / sizeof(struct scsiif_request_segment))260261/* Size of one request is 252 bytes */262struct vscsiif_request {263uint16_t rqid; /* private guest value, echoed in resp */264uint8_t act; /* command between backend and frontend */265uint8_t cmd_len; /* valid CDB bytes */266267uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */268uint16_t timeout_per_command; /* deprecated: timeout in secs, 0=default */269uint16_t channel, id, lun; /* (virtual) device specification */270uint16_t ref_rqid; /* command abort reference */271uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1)272DMA_FROM_DEVICE(2)273DMA_NONE(3) requests */274uint8_t nr_segments; /* Number of pieces of scatter-gather */275/*276* flag in nr_segments: SG elements via grant page277*278* If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number279* of grant pages containing SG elements. Usable if "feature-sg-grant" set.280*/281#define VSCSIIF_SG_GRANT 0x80282283vscsiif_segment_t seg[VSCSIIF_SG_TABLESIZE];284uint32_t reserved[3];285};286typedef struct vscsiif_request vscsiif_request_t;287288/*289* The following interface is deprecated!290*/291#define VSCSIIF_SG_LIST_SIZE ((sizeof(vscsiif_request_t) - 4) \292/ sizeof(vscsiif_segment_t))293294struct vscsiif_sg_list {295/* First two fields must match struct vscsiif_request! */296uint16_t rqid; /* private guest value, must match main req */297uint8_t act; /* VSCSIIF_ACT_SCSI_SG_PRESET */298uint8_t nr_segments; /* Number of pieces of scatter-gather */299vscsiif_segment_t seg[VSCSIIF_SG_LIST_SIZE];300};301typedef struct vscsiif_sg_list vscsiif_sg_list_t;302/* End of deprecated interface */303304/* Size of one response is 252 bytes */305struct vscsiif_response {306uint16_t rqid; /* identifies request */307uint8_t act; /* deprecated: valid only if SG_PRESET supported */308uint8_t sense_len;309uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];310int32_t rslt;311uint32_t residual_len; /* request bufflen -312return the value from physical device */313uint32_t reserved[36];314};315typedef struct vscsiif_response vscsiif_response_t;316317DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);318319320#endif /*__XEN__PUBLIC_IO_SCSI_H__*/321/*322* Local variables:323* mode: C324* c-file-style: "BSD"325* c-basic-offset: 4326* tab-width: 4327* indent-tabs-mode: nil328* End:329*/330331332