/* SPDX-License-Identifier: MIT */1/******************************************************************************2* vscsiif.h3*4* Based on the blkif.h code.5*6* Copyright(c) FUJITSU Limited 2008.7*/89#ifndef __XEN__PUBLIC_IO_SCSI_H__10#define __XEN__PUBLIC_IO_SCSI_H__1112#include "ring.h"13#include "../grant_table.h"1415/*16* Feature and Parameter Negotiation17* =================================18* The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to19* communicate capabilities and to negotiate operating parameters. This20* section enumerates these nodes which reside in the respective front and21* backend portions of the XenStore, following the XenBus convention.22*23* Any specified default value is in effect if the corresponding XenBus node24* is not present in the XenStore.25*26* XenStore nodes in sections marked "PRIVATE" are solely for use by the27* driver side whose XenBus tree contains them.28*29*****************************************************************************30* Backend XenBus Nodes31*****************************************************************************32*33*------------------ Backend Device Identification (PRIVATE) ------------------34*35* p-devname36* Values: string37*38* A free string used to identify the physical device (e.g. a disk name).39*40* p-dev41* Values: string42*43* A string specifying the backend device: either a 4-tuple "h:c:t:l"44* (host, controller, target, lun, all integers), or a WWN (e.g.45* "naa.60014054ac780582:0").46*47* v-dev48* Values: string49*50* A string specifying the frontend device in form of a 4-tuple "h:c:t:l"51* (host, controller, target, lun, all integers).52*53*--------------------------------- Features ---------------------------------54*55* feature-sg-grant56* Values: unsigned [VSCSIIF_SG_TABLESIZE...65535]57* Default Value: 058*59* Specifies the maximum number of scatter/gather elements in grant pages60* supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE61* SG elements specified directly in the request.62*63*****************************************************************************64* Frontend XenBus Nodes65*****************************************************************************66*67*----------------------- Request Transport Parameters -----------------------68*69* event-channel70* Values: unsigned71*72* The identifier of the Xen event channel used to signal activity73* in the ring buffer.74*75* ring-ref76* Values: unsigned77*78* The Xen grant reference granting permission for the backend to map79* the sole page in a single page sized ring buffer.80*81* protocol82* Values: string (XEN_IO_PROTO_ABI_*)83* Default Value: XEN_IO_PROTO_ABI_NATIVE84*85* The machine ABI rules governing the format of all ring request and86* response structures.87*/8889/*90* Xenstore format in practice91* ===========================92*93* The backend driver uses a single_host:many_devices notation to manage domU94* devices. Everything is stored in /local/domain/<backend_domid>/backend/vscsi/.95* The xenstore layout looks like this (dom0 is assumed to be the backend_domid):96*97* <domid>/<vhost>/feature-host = "0"98* <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"99* <domid>/<vhost>/frontend-id = "<domid>"100* <domid>/<vhost>/online = "1"101* <domid>/<vhost>/state = "4"102* <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1" or "naa.wwn:lun"103* <domid>/<vhost>/vscsi-devs/dev-0/state = "4"104* <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"105* <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"106* <domid>/<vhost>/vscsi-devs/dev-1/state = "4"107* <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"108*109* The frontend driver maintains its state in110* /local/domain/<domid>/device/vscsi/.111*112* <vhost>/backend = "/local/domain/0/backend/vscsi/<domid>/<vhost>"113* <vhost>/backend-id = "0"114* <vhost>/event-channel = "20"115* <vhost>/ring-ref = "43"116* <vhost>/state = "4"117* <vhost>/vscsi-devs/dev-0/state = "4"118* <vhost>/vscsi-devs/dev-1/state = "4"119*120* In addition to the entries for backend and frontend these flags are stored121* for the toolstack:122*123* <domid>/<vhost>/vscsi-devs/dev-1/p-devname = "/dev/$device"124* <domid>/<vhost>/libxl_ctrl_index = "0"125*126*127* Backend/frontend protocol128* =========================129*130* To create a vhost along with a device:131* <domid>/<vhost>/feature-host = "0"132* <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"133* <domid>/<vhost>/frontend-id = "<domid>"134* <domid>/<vhost>/online = "1"135* <domid>/<vhost>/state = "1"136* <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1"137* <domid>/<vhost>/vscsi-devs/dev-0/state = "1"138* <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"139* Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-0/state become 4140*141* To add another device to a vhost:142* <domid>/<vhost>/state = "7"143* <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"144* <domid>/<vhost>/vscsi-devs/dev-1/state = "1"145* <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"146* Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-1/state become 4147*148* To remove a device from a vhost:149* <domid>/<vhost>/state = "7"150* <domid>/<vhost>/vscsi-devs/dev-1/state = "5"151* Wait for <domid>/<vhost>/state to become 4152* Wait for <domid>/<vhost>/vscsi-devs/dev-1/state become 6153* Remove <domid>/<vhost>/vscsi-devs/dev-1/{state,p-dev,v-dev,p-devname}154* Remove <domid>/<vhost>/vscsi-devs/dev-1/155*156*/157158/* Requests from the frontend to the backend */159160/*161* Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.162* The target is specified via channel, id and lun.163*164* The operation to be performed is specified via a CDB in cmnd[], the length165* of the CDB is in cmd_len. sc_data_direction specifies the direction of data166* (to the device, from the device, or none at all).167*168* If data is to be transferred to or from the device the buffer(s) in the169* guest memory is/are specified via one or multiple scsiif_request_segment170* descriptors each specifying a memory page via a grant_ref_t, a offset into171* the page and the length of the area in that page. All scsiif_request_segment172* areas concatenated form the resulting data buffer used by the operation.173* If the number of scsiif_request_segment areas is not too large (less than174* or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the175* seg[] array and the number of valid scsiif_request_segment elements is to be176* set in nr_segments.177*178* If "feature-sg-grant" in the Xenstore is set it is possible to specify more179* than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection.180* The maximum number of allowed scsiif_request_segment elements is the value181* of the "feature-sg-grant" entry from Xenstore. When using indirection the182* seg[] array doesn't contain specifications of the data buffers, but183* references to scsiif_request_segment arrays, which in turn reference the184* data buffers. While nr_segments holds the number of populated seg[] entries185* (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment186* elements referencing the target data buffers is calculated from the lengths187* of the seg[] elements (the sum of all valid seg[].length divided by the188* size of one scsiif_request_segment structure). The frontend may use a mix of189* direct and indirect requests.190*/191#define VSCSIIF_ACT_SCSI_CDB 1192193/*194* Request abort of a running operation for the specified target given by195* channel, id, lun and the operation's rqid in ref_rqid.196*/197#define VSCSIIF_ACT_SCSI_ABORT 2198199/*200* Request a device reset of the specified target (channel and id).201*/202#define VSCSIIF_ACT_SCSI_RESET 3203204/*205* Preset scatter/gather elements for a following request. Deprecated.206* Keeping the define only to avoid usage of the value "4" for other actions.207*/208#define VSCSIIF_ACT_SCSI_SG_PRESET 4209210/*211* Maximum scatter/gather segments per request.212*213* Considering balance between allocating at least 16 "vscsiif_request"214* structures on one page (4096 bytes) and the number of scatter/gather215* elements needed, we decided to use 26 as a magic number.216*217* If "feature-sg-grant" is set, more scatter/gather elements can be specified218* by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages.219* In this case the vscsiif_request seg elements don't contain references to220* the user data, but to the SG elements referencing the user data.221*/222#define VSCSIIF_SG_TABLESIZE 26223224/*225* based on Linux kernel 2.6.18, still valid226*227* Changing these values requires support of multiple protocols via the rings228* as "old clients" will blindly use these values and the resulting structure229* sizes.230*/231#define VSCSIIF_MAX_COMMAND_SIZE 16232#define VSCSIIF_SENSE_BUFFERSIZE 96233#define VSCSIIF_PAGE_SIZE 4096234235struct scsiif_request_segment {236grant_ref_t gref;237uint16_t offset;238uint16_t length;239};240241#define VSCSIIF_SG_PER_PAGE (VSCSIIF_PAGE_SIZE / \242sizeof(struct scsiif_request_segment))243244/* Size of one request is 252 bytes */245struct vscsiif_request {246uint16_t rqid; /* private guest value, echoed in resp */247uint8_t act; /* command between backend and frontend */248uint8_t cmd_len; /* valid CDB bytes */249250uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */251uint16_t timeout_per_command; /* deprecated */252uint16_t channel, id, lun; /* (virtual) device specification */253uint16_t ref_rqid; /* command abort reference */254uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1)255DMA_FROM_DEVICE(2)256DMA_NONE(3) requests */257uint8_t nr_segments; /* Number of pieces of scatter-gather */258/*259* flag in nr_segments: SG elements via grant page260*261* If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number262* of grant pages containing SG elements. Usable if "feature-sg-grant" set.263*/264#define VSCSIIF_SG_GRANT 0x80265266struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE];267uint32_t reserved[3];268};269270/* Size of one response is 252 bytes */271struct vscsiif_response {272uint16_t rqid; /* identifies request */273uint8_t padding;274uint8_t sense_len;275uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];276int32_t rslt;277uint32_t residual_len; /* request bufflen -278return the value from physical device */279uint32_t reserved[36];280};281282/* SCSI I/O status from vscsiif_response->rslt */283#define XEN_VSCSIIF_RSLT_STATUS(x) ((x) & 0x00ff)284285/* Host I/O status from vscsiif_response->rslt */286#define XEN_VSCSIIF_RSLT_HOST(x) (((x) & 0x00ff0000) >> 16)287#define XEN_VSCSIIF_RSLT_HOST_OK 0288/* Couldn't connect before timeout */289#define XEN_VSCSIIF_RSLT_HOST_NO_CONNECT 1290/* Bus busy through timeout */291#define XEN_VSCSIIF_RSLT_HOST_BUS_BUSY 2292/* Timed out for other reason */293#define XEN_VSCSIIF_RSLT_HOST_TIME_OUT 3294/* Bad target */295#define XEN_VSCSIIF_RSLT_HOST_BAD_TARGET 4296/* Abort for some other reason */297#define XEN_VSCSIIF_RSLT_HOST_ABORT 5298/* Parity error */299#define XEN_VSCSIIF_RSLT_HOST_PARITY 6300/* Internal error */301#define XEN_VSCSIIF_RSLT_HOST_ERROR 7302/* Reset by somebody */303#define XEN_VSCSIIF_RSLT_HOST_RESET 8304/* Unexpected interrupt */305#define XEN_VSCSIIF_RSLT_HOST_BAD_INTR 9306/* Force command past mid-layer */307#define XEN_VSCSIIF_RSLT_HOST_PASSTHROUGH 10308/* Retry requested */309#define XEN_VSCSIIF_RSLT_HOST_SOFT_ERROR 11310/* Hidden retry requested */311#define XEN_VSCSIIF_RSLT_HOST_IMM_RETRY 12312/* Requeue command requested */313#define XEN_VSCSIIF_RSLT_HOST_REQUEUE 13314/* Transport error disrupted I/O */315#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_DISRUPTED 14316/* Transport class fastfailed */317#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_FAILFAST 15318/* Permanent target failure */319#define XEN_VSCSIIF_RSLT_HOST_TARGET_FAILURE 16320/* Permanent nexus failure on path */321#define XEN_VSCSIIF_RSLT_HOST_NEXUS_FAILURE 17322/* Space allocation on device failed */323#define XEN_VSCSIIF_RSLT_HOST_ALLOC_FAILURE 18324/* Medium error */325#define XEN_VSCSIIF_RSLT_HOST_MEDIUM_ERROR 19326/* Transport marginal errors */327#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_MARGINAL 20328329/* Result values of reset operations */330#define XEN_VSCSIIF_RSLT_RESET_SUCCESS 0x2002331#define XEN_VSCSIIF_RSLT_RESET_FAILED 0x2003332333DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);334335336#endif /*__XEN__PUBLIC_IO_SCSI_H__*/337338339