18c2ecf20Sopenharmony_ci/****************************************************************************** 28c2ecf20Sopenharmony_ci * vscsiif.h 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Based on the blkif.h code. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 78c2ecf20Sopenharmony_ci * of this software and associated documentation files (the "Software"), to 88c2ecf20Sopenharmony_ci * deal in the Software without restriction, including without limitation the 98c2ecf20Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 108c2ecf20Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 118c2ecf20Sopenharmony_ci * furnished to do so, subject to the following conditions: 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 148c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 178c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 188c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 198c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 208c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 218c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 228c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * Copyright(c) FUJITSU Limited 2008. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#ifndef __XEN__PUBLIC_IO_SCSI_H__ 288c2ecf20Sopenharmony_ci#define __XEN__PUBLIC_IO_SCSI_H__ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include "ring.h" 318c2ecf20Sopenharmony_ci#include "../grant_table.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 348c2ecf20Sopenharmony_ci * Feature and Parameter Negotiation 358c2ecf20Sopenharmony_ci * ================================= 368c2ecf20Sopenharmony_ci * The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to 378c2ecf20Sopenharmony_ci * communicate capabilities and to negotiate operating parameters. This 388c2ecf20Sopenharmony_ci * section enumerates these nodes which reside in the respective front and 398c2ecf20Sopenharmony_ci * backend portions of the XenStore, following the XenBus convention. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * Any specified default value is in effect if the corresponding XenBus node 428c2ecf20Sopenharmony_ci * is not present in the XenStore. 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * XenStore nodes in sections marked "PRIVATE" are solely for use by the 458c2ecf20Sopenharmony_ci * driver side whose XenBus tree contains them. 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci ***************************************************************************** 488c2ecf20Sopenharmony_ci * Backend XenBus Nodes 498c2ecf20Sopenharmony_ci ***************************************************************************** 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci *------------------ Backend Device Identification (PRIVATE) ------------------ 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * p-devname 548c2ecf20Sopenharmony_ci * Values: string 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * A free string used to identify the physical device (e.g. a disk name). 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * p-dev 598c2ecf20Sopenharmony_ci * Values: string 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * A string specifying the backend device: either a 4-tuple "h:c:t:l" 628c2ecf20Sopenharmony_ci * (host, controller, target, lun, all integers), or a WWN (e.g. 638c2ecf20Sopenharmony_ci * "naa.60014054ac780582"). 648c2ecf20Sopenharmony_ci * 658c2ecf20Sopenharmony_ci * v-dev 668c2ecf20Sopenharmony_ci * Values: string 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * A string specifying the frontend device in form of a 4-tuple "h:c:t:l" 698c2ecf20Sopenharmony_ci * (host, controller, target, lun, all integers). 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci *--------------------------------- Features --------------------------------- 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * feature-sg-grant 748c2ecf20Sopenharmony_ci * Values: unsigned [VSCSIIF_SG_TABLESIZE...65535] 758c2ecf20Sopenharmony_ci * Default Value: 0 768c2ecf20Sopenharmony_ci * 778c2ecf20Sopenharmony_ci * Specifies the maximum number of scatter/gather elements in grant pages 788c2ecf20Sopenharmony_ci * supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE 798c2ecf20Sopenharmony_ci * SG elements specified directly in the request. 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci ***************************************************************************** 828c2ecf20Sopenharmony_ci * Frontend XenBus Nodes 838c2ecf20Sopenharmony_ci ***************************************************************************** 848c2ecf20Sopenharmony_ci * 858c2ecf20Sopenharmony_ci *----------------------- Request Transport Parameters ----------------------- 868c2ecf20Sopenharmony_ci * 878c2ecf20Sopenharmony_ci * event-channel 888c2ecf20Sopenharmony_ci * Values: unsigned 898c2ecf20Sopenharmony_ci * 908c2ecf20Sopenharmony_ci * The identifier of the Xen event channel used to signal activity 918c2ecf20Sopenharmony_ci * in the ring buffer. 928c2ecf20Sopenharmony_ci * 938c2ecf20Sopenharmony_ci * ring-ref 948c2ecf20Sopenharmony_ci * Values: unsigned 958c2ecf20Sopenharmony_ci * 968c2ecf20Sopenharmony_ci * The Xen grant reference granting permission for the backend to map 978c2ecf20Sopenharmony_ci * the sole page in a single page sized ring buffer. 988c2ecf20Sopenharmony_ci * 998c2ecf20Sopenharmony_ci * protocol 1008c2ecf20Sopenharmony_ci * Values: string (XEN_IO_PROTO_ABI_*) 1018c2ecf20Sopenharmony_ci * Default Value: XEN_IO_PROTO_ABI_NATIVE 1028c2ecf20Sopenharmony_ci * 1038c2ecf20Sopenharmony_ci * The machine ABI rules governing the format of all ring request and 1048c2ecf20Sopenharmony_ci * response structures. 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* Requests from the frontend to the backend */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* 1108c2ecf20Sopenharmony_ci * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd. 1118c2ecf20Sopenharmony_ci * The target is specified via channel, id and lun. 1128c2ecf20Sopenharmony_ci * 1138c2ecf20Sopenharmony_ci * The operation to be performed is specified via a CDB in cmnd[], the length 1148c2ecf20Sopenharmony_ci * of the CDB is in cmd_len. sc_data_direction specifies the direction of data 1158c2ecf20Sopenharmony_ci * (to the device, from the device, or none at all). 1168c2ecf20Sopenharmony_ci * 1178c2ecf20Sopenharmony_ci * If data is to be transferred to or from the device the buffer(s) in the 1188c2ecf20Sopenharmony_ci * guest memory is/are specified via one or multiple scsiif_request_segment 1198c2ecf20Sopenharmony_ci * descriptors each specifying a memory page via a grant_ref_t, a offset into 1208c2ecf20Sopenharmony_ci * the page and the length of the area in that page. All scsiif_request_segment 1218c2ecf20Sopenharmony_ci * areas concatenated form the resulting data buffer used by the operation. 1228c2ecf20Sopenharmony_ci * If the number of scsiif_request_segment areas is not too large (less than 1238c2ecf20Sopenharmony_ci * or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the 1248c2ecf20Sopenharmony_ci * seg[] array and the number of valid scsiif_request_segment elements is to be 1258c2ecf20Sopenharmony_ci * set in nr_segments. 1268c2ecf20Sopenharmony_ci * 1278c2ecf20Sopenharmony_ci * If "feature-sg-grant" in the Xenstore is set it is possible to specify more 1288c2ecf20Sopenharmony_ci * than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection. 1298c2ecf20Sopenharmony_ci * The maximum number of allowed scsiif_request_segment elements is the value 1308c2ecf20Sopenharmony_ci * of the "feature-sg-grant" entry from Xenstore. When using indirection the 1318c2ecf20Sopenharmony_ci * seg[] array doesn't contain specifications of the data buffers, but 1328c2ecf20Sopenharmony_ci * references to scsiif_request_segment arrays, which in turn reference the 1338c2ecf20Sopenharmony_ci * data buffers. While nr_segments holds the number of populated seg[] entries 1348c2ecf20Sopenharmony_ci * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment 1358c2ecf20Sopenharmony_ci * elements referencing the target data buffers is calculated from the lengths 1368c2ecf20Sopenharmony_ci * of the seg[] elements (the sum of all valid seg[].length divided by the 1378c2ecf20Sopenharmony_ci * size of one scsiif_request_segment structure). 1388c2ecf20Sopenharmony_ci */ 1398c2ecf20Sopenharmony_ci#define VSCSIIF_ACT_SCSI_CDB 1 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/* 1428c2ecf20Sopenharmony_ci * Request abort of a running operation for the specified target given by 1438c2ecf20Sopenharmony_ci * channel, id, lun and the operation's rqid in ref_rqid. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ci#define VSCSIIF_ACT_SCSI_ABORT 2 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* 1488c2ecf20Sopenharmony_ci * Request a device reset of the specified target (channel and id). 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_ci#define VSCSIIF_ACT_SCSI_RESET 3 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci/* 1538c2ecf20Sopenharmony_ci * Preset scatter/gather elements for a following request. Deprecated. 1548c2ecf20Sopenharmony_ci * Keeping the define only to avoid usage of the value "4" for other actions. 1558c2ecf20Sopenharmony_ci */ 1568c2ecf20Sopenharmony_ci#define VSCSIIF_ACT_SCSI_SG_PRESET 4 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/* 1598c2ecf20Sopenharmony_ci * Maximum scatter/gather segments per request. 1608c2ecf20Sopenharmony_ci * 1618c2ecf20Sopenharmony_ci * Considering balance between allocating at least 16 "vscsiif_request" 1628c2ecf20Sopenharmony_ci * structures on one page (4096 bytes) and the number of scatter/gather 1638c2ecf20Sopenharmony_ci * elements needed, we decided to use 26 as a magic number. 1648c2ecf20Sopenharmony_ci * 1658c2ecf20Sopenharmony_ci * If "feature-sg-grant" is set, more scatter/gather elements can be specified 1668c2ecf20Sopenharmony_ci * by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages. 1678c2ecf20Sopenharmony_ci * In this case the vscsiif_request seg elements don't contain references to 1688c2ecf20Sopenharmony_ci * the user data, but to the SG elements referencing the user data. 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_ci#define VSCSIIF_SG_TABLESIZE 26 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci/* 1738c2ecf20Sopenharmony_ci * based on Linux kernel 2.6.18, still valid 1748c2ecf20Sopenharmony_ci * Changing these values requires support of multiple protocols via the rings 1758c2ecf20Sopenharmony_ci * as "old clients" will blindly use these values and the resulting structure 1768c2ecf20Sopenharmony_ci * sizes. 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_ci#define VSCSIIF_MAX_COMMAND_SIZE 16 1798c2ecf20Sopenharmony_ci#define VSCSIIF_SENSE_BUFFERSIZE 96 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistruct scsiif_request_segment { 1828c2ecf20Sopenharmony_ci grant_ref_t gref; 1838c2ecf20Sopenharmony_ci uint16_t offset; 1848c2ecf20Sopenharmony_ci uint16_t length; 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segment)) 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* Size of one request is 252 bytes */ 1908c2ecf20Sopenharmony_cistruct vscsiif_request { 1918c2ecf20Sopenharmony_ci uint16_t rqid; /* private guest value, echoed in resp */ 1928c2ecf20Sopenharmony_ci uint8_t act; /* command between backend and frontend */ 1938c2ecf20Sopenharmony_ci uint8_t cmd_len; /* valid CDB bytes */ 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */ 1968c2ecf20Sopenharmony_ci uint16_t timeout_per_command; /* deprecated */ 1978c2ecf20Sopenharmony_ci uint16_t channel, id, lun; /* (virtual) device specification */ 1988c2ecf20Sopenharmony_ci uint16_t ref_rqid; /* command abort reference */ 1998c2ecf20Sopenharmony_ci uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1) 2008c2ecf20Sopenharmony_ci DMA_FROM_DEVICE(2) 2018c2ecf20Sopenharmony_ci DMA_NONE(3) requests */ 2028c2ecf20Sopenharmony_ci uint8_t nr_segments; /* Number of pieces of scatter-gather */ 2038c2ecf20Sopenharmony_ci/* 2048c2ecf20Sopenharmony_ci * flag in nr_segments: SG elements via grant page 2058c2ecf20Sopenharmony_ci * 2068c2ecf20Sopenharmony_ci * If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number 2078c2ecf20Sopenharmony_ci * of grant pages containing SG elements. Usable if "feature-sg-grant" set. 2088c2ecf20Sopenharmony_ci */ 2098c2ecf20Sopenharmony_ci#define VSCSIIF_SG_GRANT 0x80 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE]; 2128c2ecf20Sopenharmony_ci uint32_t reserved[3]; 2138c2ecf20Sopenharmony_ci}; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* Size of one response is 252 bytes */ 2168c2ecf20Sopenharmony_cistruct vscsiif_response { 2178c2ecf20Sopenharmony_ci uint16_t rqid; /* identifies request */ 2188c2ecf20Sopenharmony_ci uint8_t padding; 2198c2ecf20Sopenharmony_ci uint8_t sense_len; 2208c2ecf20Sopenharmony_ci uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE]; 2218c2ecf20Sopenharmony_ci int32_t rslt; 2228c2ecf20Sopenharmony_ci uint32_t residual_len; /* request bufflen - 2238c2ecf20Sopenharmony_ci return the value from physical device */ 2248c2ecf20Sopenharmony_ci uint32_t reserved[36]; 2258c2ecf20Sopenharmony_ci}; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ciDEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci#endif /*__XEN__PUBLIC_IO_SCSI_H__*/ 230