blkif.h revision 232308
1181624Skmacy/****************************************************************************** 2181624Skmacy * blkif.h 3231743Sgibbs * 4181624Skmacy * Unified block-device I/O interface for Xen guest OSes. 5231743Sgibbs * 6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 7181624Skmacy * of this software and associated documentation files (the "Software"), to 8181624Skmacy * deal in the Software without restriction, including without limitation the 9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is 11181624Skmacy * furnished to do so, subject to the following conditions: 12181624Skmacy * 13181624Skmacy * The above copyright notice and this permission notice shall be included in 14181624Skmacy * all copies or substantial portions of the Software. 15181624Skmacy * 16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22181624Skmacy * DEALINGS IN THE SOFTWARE. 23181624Skmacy * 24181624Skmacy * Copyright (c) 2003-2004, Keir Fraser 25231743Sgibbs * Copyright (c) 2012, Spectra Logic Corporation 26181624Skmacy */ 27181624Skmacy 28181624Skmacy#ifndef __XEN_PUBLIC_IO_BLKIF_H__ 29181624Skmacy#define __XEN_PUBLIC_IO_BLKIF_H__ 30181624Skmacy 31181624Skmacy#include <xen/interface/io/ring.h> 32181624Skmacy#include <xen/interface/grant_table.h> 33181624Skmacy 34181624Skmacy/* 35181624Skmacy * Front->back notifications: When enqueuing a new request, sending a 36181624Skmacy * notification can be made conditional on req_event (i.e., the generic 37181624Skmacy * hold-off mechanism provided by the ring macros). Backends must set 38181624Skmacy * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()). 39231743Sgibbs * 40181624Skmacy * Back->front notifications: When enqueuing a new response, sending a 41181624Skmacy * notification can be made conditional on rsp_event (i.e., the generic 42181624Skmacy * hold-off mechanism provided by the ring macros). Frontends must set 43181624Skmacy * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()). 44181624Skmacy */ 45181624Skmacy 46181624Skmacy#ifndef blkif_vdev_t 47181624Skmacy#define blkif_vdev_t uint16_t 48181624Skmacy#endif 49181624Skmacy#define blkif_sector_t uint64_t 50181624Skmacy 51181624Skmacy/* 52231743Sgibbs * Feature and Parameter Negotiation 53231743Sgibbs * ================================= 54231743Sgibbs * The two halves of a Xen block driver utilize nodes within the XenStore to 55231743Sgibbs * communicate capabilities and to negotiate operating parameters. This 56231743Sgibbs * section enumerates these nodes which reside in the respective front and 57231743Sgibbs * backend portions of the XenStore, following the XenBus convention. 58231743Sgibbs * 59231743Sgibbs * All data in the XenStore is stored as strings. Nodes specifying numeric 60231743Sgibbs * values are encoded in decimal. Integer value ranges listed below are 61231743Sgibbs * expressed as fixed sized integer types capable of storing the conversion 62232308Sgibbs * of a properly formatted node string, without loss of information. 63231743Sgibbs * 64231743Sgibbs * Any specified default value is in effect if the corresponding XenBus node 65231743Sgibbs * is not present in the XenStore. 66231743Sgibbs * 67231743Sgibbs * XenStore nodes in sections marked "PRIVATE" are solely for use by the 68231743Sgibbs * driver side whose XenBus tree contains them. 69231743Sgibbs * 70232308Sgibbs * XenStore nodes marked "DEPRECATED" in their notes section should only be 71232308Sgibbs * used to provide interoperability with legacy implementations. 72232308Sgibbs * 73231743Sgibbs * See the XenBus state transition diagram below for details on when XenBus 74231743Sgibbs * nodes must be published and when they can be queried. 75231743Sgibbs * 76231743Sgibbs ***************************************************************************** 77231743Sgibbs * Backend XenBus Nodes 78231743Sgibbs ***************************************************************************** 79231743Sgibbs * 80231743Sgibbs *------------------ Backend Device Identification (PRIVATE) ------------------ 81231743Sgibbs * 82231743Sgibbs * mode 83231743Sgibbs * Values: "r" (read only), "w" (writable) 84231743Sgibbs * 85231743Sgibbs * The read or write access permissions to the backing store to be 86231743Sgibbs * granted to the frontend. 87231743Sgibbs * 88231743Sgibbs * params 89231743Sgibbs * Values: string 90231743Sgibbs * 91232308Sgibbs * Data used by the backend driver to locate and configure the backing 92232308Sgibbs * device. The format and semantics of this data vary according to the 93232308Sgibbs * backing device in use and are outside the scope of this specification. 94231743Sgibbs * 95231743Sgibbs * type 96231743Sgibbs * Values: "file", "phy", "tap" 97231743Sgibbs * 98231743Sgibbs * The type of the backing device/object. 99231743Sgibbs * 100231743Sgibbs *--------------------------------- Features --------------------------------- 101231743Sgibbs * 102231743Sgibbs * feature-barrier 103231743Sgibbs * Values: 0/1 (boolean) 104231743Sgibbs * Default Value: 0 105231743Sgibbs * 106231743Sgibbs * A value of "1" indicates that the backend can process requests 107231743Sgibbs * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests 108231743Sgibbs * of this type may still be returned at any time with the 109231743Sgibbs * BLKIF_RSP_EOPNOTSUPP result code. 110231743Sgibbs * 111231743Sgibbs * feature-flush-cache 112231743Sgibbs * Values: 0/1 (boolean) 113231743Sgibbs * Default Value: 0 114231743Sgibbs * 115231743Sgibbs * A value of "1" indicates that the backend can process requests 116231743Sgibbs * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests 117231743Sgibbs * of this type may still be returned at any time with the 118231743Sgibbs * BLKIF_RSP_EOPNOTSUPP result code. 119231743Sgibbs * 120231743Sgibbs * feature-discard 121231743Sgibbs * Values: 0/1 (boolean) 122231743Sgibbs * Default Value: 0 123231743Sgibbs * 124231743Sgibbs * A value of "1" indicates that the backend can process requests 125231743Sgibbs * containing the BLKIF_OP_DISCARD request opcode. Requests 126231743Sgibbs * of this type may still be returned at any time with the 127231743Sgibbs * BLKIF_RSP_EOPNOTSUPP result code. 128231743Sgibbs * 129231743Sgibbs *----------------------- Request Transport Parameters ------------------------ 130231743Sgibbs * 131231743Sgibbs * max-ring-page-order 132231743Sgibbs * Values: <uint32_t> 133231743Sgibbs * Default Value: 0 134231743Sgibbs * Notes: 1, 3 135231743Sgibbs * 136231743Sgibbs * The maximum supported size of the request ring buffer in units of 137231743Sgibbs * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, 138231743Sgibbs * etc.). 139231743Sgibbs * 140231743Sgibbs * max-ring-pages 141231743Sgibbs * Values: <uint32_t> 142231743Sgibbs * Default Value: 1 143232308Sgibbs * Notes: DEPRECATED, 2, 3 144231743Sgibbs * 145231743Sgibbs * The maximum supported size of the request ring buffer in units of 146231743Sgibbs * machine pages. The value must be a power of 2. 147231743Sgibbs * 148231743Sgibbs * max-requests <uint32_t> 149231743Sgibbs * Default Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE) 150231743Sgibbs * Maximum Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages) 151231743Sgibbs * 152232308Sgibbs * The maximum number of concurrent, logical requests supported by 153232308Sgibbs * the backend. 154231743Sgibbs * 155231743Sgibbs * Note: A logical request may span multiple ring entries. 156231743Sgibbs * 157231743Sgibbs * max-request-segments 158231743Sgibbs * Values: <uint8_t> 159231743Sgibbs * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 160231743Sgibbs * Maximum Value: BLKIF_MAX_SEGMENTS_PER_REQUEST 161231743Sgibbs * 162231743Sgibbs * The maximum value of blkif_request.nr_segments supported by 163231743Sgibbs * the backend. 164231743Sgibbs * 165231743Sgibbs * max-request-size 166231743Sgibbs * Values: <uint32_t> 167231743Sgibbs * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE 168231743Sgibbs * Maximum Value: BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE 169231743Sgibbs * 170231743Sgibbs * The maximum amount of data, in bytes, that can be referenced by a 171231743Sgibbs * request type that accesses frontend memory (currently BLKIF_OP_READ, 172231743Sgibbs * BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER). 173231743Sgibbs * 174231743Sgibbs *------------------------- Backend Device Properties ------------------------- 175231743Sgibbs * 176232308Sgibbs * discard-alignment 177231743Sgibbs * Values: <uint32_t> 178231743Sgibbs * Default Value: 0 179231743Sgibbs * Notes: 4, 5 180231743Sgibbs * 181231743Sgibbs * The offset, in bytes from the beginning of the virtual block device, 182231743Sgibbs * to the first, addressable, discard extent on the underlying device. 183231743Sgibbs * 184231743Sgibbs * discard-granularity 185231743Sgibbs * Values: <uint32_t> 186231743Sgibbs * Default Value: <"sector-size"> 187231743Sgibbs * Notes: 4 188231743Sgibbs * 189231743Sgibbs * The size, in bytes, of the individually addressable discard extents 190231743Sgibbs * of the underlying device. 191231743Sgibbs * 192231743Sgibbs * discard-secure 193231743Sgibbs * Values: 0/1 (boolean) 194231743Sgibbs * Default Value: 0 195231743Sgibbs * 196231743Sgibbs * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD 197231743Sgibbs * requests with the BLKIF_DISCARD_SECURE flag set. 198231743Sgibbs * 199231743Sgibbs * info 200231743Sgibbs * Values: <uint32_t> (bitmap) 201231743Sgibbs * 202231743Sgibbs * A collection of bit flags describing attributes of the backing 203231743Sgibbs * device. The VDISK_* macros define the meaning of each bit 204231743Sgibbs * location. 205231743Sgibbs * 206231743Sgibbs * sector-size 207231743Sgibbs * Values: <uint32_t> 208231743Sgibbs * 209232308Sgibbs * The size, in bytes, of the individually addressible data blocks 210232308Sgibbs * on the backend device. 211231743Sgibbs * 212231743Sgibbs * sectors 213231743Sgibbs * Values: <uint64_t> 214231743Sgibbs * 215231743Sgibbs * The size of the backend device, expressed in units of its native 216231743Sgibbs * sector size ("sector-size"). 217231743Sgibbs * 218231743Sgibbs ***************************************************************************** 219231743Sgibbs * Frontend XenBus Nodes 220231743Sgibbs ***************************************************************************** 221231743Sgibbs * 222231743Sgibbs *----------------------- Request Transport Parameters ----------------------- 223231743Sgibbs * 224231743Sgibbs * event-channel 225231743Sgibbs * Values: <uint32_t> 226231743Sgibbs * 227231743Sgibbs * The identifier of the Xen event channel used to signal activity 228231743Sgibbs * in the ring buffer. 229231743Sgibbs * 230231743Sgibbs * ring-ref 231231743Sgibbs * Values: <uint32_t> 232231743Sgibbs * Notes: 6 233231743Sgibbs * 234231743Sgibbs * The Xen grant reference granting permission for the backend to map 235231743Sgibbs * the sole page in a single page sized ring buffer. 236231743Sgibbs * 237231743Sgibbs * ring-ref%u 238231743Sgibbs * Values: <uint32_t> 239231743Sgibbs * Notes: 6 240231743Sgibbs * 241232308Sgibbs * For a frontend providing a multi-page ring, a "number of ring pages" 242232308Sgibbs * sized list of nodes, each containing a Xen grant reference granting 243231743Sgibbs * permission for the backend to map the page of the ring located 244231743Sgibbs * at page index "%u". Page indexes are zero based. 245231743Sgibbs * 246231743Sgibbs * protocol 247231743Sgibbs * Values: string (XEN_IO_PROTO_ABI_*) 248231743Sgibbs * Default Value: XEN_IO_PROTO_ABI_NATIVE 249231743Sgibbs * 250231743Sgibbs * The machine ABI rules governing the format of all ring request and 251231743Sgibbs * response structures. 252231743Sgibbs * 253231743Sgibbs * ring-page-order 254231743Sgibbs * Values: <uint32_t> 255231743Sgibbs * Default Value: 0 256231743Sgibbs * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order) 257231743Sgibbs * Notes: 1, 3 258231743Sgibbs * 259231743Sgibbs * The size of the frontend allocated request ring buffer in units 260231743Sgibbs * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, 261231743Sgibbs * etc.). 262231743Sgibbs * 263231743Sgibbs * num-ring-pages 264231743Sgibbs * Values: <uint32_t> 265231743Sgibbs * Default Value: 1 266231743Sgibbs * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order)) 267232308Sgibbs * Notes: DEPRECATED, 2, 3 268231743Sgibbs * 269231743Sgibbs * The size of the frontend allocated request ring buffer in units of 270231743Sgibbs * machine pages. The value must be a power of 2. 271231743Sgibbs * 272231743Sgibbs * max-requests 273231743Sgibbs * Values: <uint32_t> 274231743Sgibbs * Default Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE) 275231836Sgibbs * Maximum Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages) 276231743Sgibbs * 277231743Sgibbs * The maximum number of concurrent, logical requests that will be 278231743Sgibbs * issued by the frontend. 279231743Sgibbs * 280231743Sgibbs * Note: A logical request may span multiple ring entries. 281231743Sgibbs * 282231743Sgibbs * max-request-segments 283231743Sgibbs * Values: <uint8_t> 284231743Sgibbs * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 285231743Sgibbs * Maximum Value: MIN(255, backend/max-request-segments) 286231743Sgibbs * 287231743Sgibbs * The maximum value the frontend will set in the 288231743Sgibbs * blkif_request.nr_segments field. 289231743Sgibbs * 290231743Sgibbs * max-request-size 291231743Sgibbs * Values: <uint32_t> 292231743Sgibbs * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE 293231743Sgibbs * Maximum Value: max-request-segments * PAGE_SIZE 294231743Sgibbs * 295231743Sgibbs * The maximum amount of data, in bytes, that can be referenced by 296231743Sgibbs * a request type that accesses frontend memory (currently BLKIF_OP_READ, 297231743Sgibbs * BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER). 298231743Sgibbs * 299231743Sgibbs *------------------------- Virtual Device Properties ------------------------- 300231743Sgibbs * 301231743Sgibbs * device-type 302231743Sgibbs * Values: "disk", "cdrom", "floppy", etc. 303231743Sgibbs * 304231743Sgibbs * virtual-device 305231743Sgibbs * Values: <uint32_t> 306231743Sgibbs * 307231743Sgibbs * A value indicating the physical device to virtualize within the 308231743Sgibbs * frontend's domain. (e.g. "The first ATA disk", "The third SCSI 309231743Sgibbs * disk", etc.) 310231743Sgibbs * 311231743Sgibbs * See docs/misc/vbd-interface.txt for details on the format of this 312231743Sgibbs * value. 313231743Sgibbs * 314231743Sgibbs * Notes 315231743Sgibbs * ----- 316231743Sgibbs * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer 317231743Sgibbs * PV drivers. 318232308Sgibbs * (2) Multi-page ring buffer scheme first used in some Red Hat distributions 319231743Sgibbs * including a distribution deployed on certain nodes of the Amazon 320231743Sgibbs * EC2 cluster. 321231743Sgibbs * (3) Support for multi-page ring buffers was implemented independently, 322232308Sgibbs * in slightly different forms, by both Citrix and Red Hat/Amazon. 323231743Sgibbs * For full interoperability, block front and backends should publish 324231743Sgibbs * identical ring parameters, adjusted for unit differences, to the 325231743Sgibbs * XenStore nodes used in both schemes. 326231743Sgibbs * (4) Devices that support discard functionality may internally allocate 327231743Sgibbs * space (discardable extents) in units that are larger than the 328231743Sgibbs * exported logical block size. 329231743Sgibbs * (5) The discard-alignment parameter allows a physical device to be 330231743Sgibbs * partitioned into virtual devices that do not necessarily begin or 331231743Sgibbs * end on a discardable extent boundary. 332231743Sgibbs * (6) When there is only a single page allocated to the request ring, 333231743Sgibbs * 'ring-ref' is used to communicate the grant reference for this 334231743Sgibbs * page to the backend. When using a multi-page ring, the 'ring-ref' 335231743Sgibbs * node is not created. Instead 'ring-ref0' - 'ring-refN' are used. 336231743Sgibbs */ 337231743Sgibbs 338231743Sgibbs/* 339231743Sgibbs * STATE DIAGRAMS 340231743Sgibbs * 341231743Sgibbs ***************************************************************************** 342231743Sgibbs * Startup * 343231743Sgibbs ***************************************************************************** 344231743Sgibbs * 345231743Sgibbs * Tool stack creates front and back nodes with state XenbusStateInitialising. 346231743Sgibbs * 347231743Sgibbs * Front Back 348231743Sgibbs * ================================= ===================================== 349231743Sgibbs * XenbusStateInitialising XenbusStateInitialising 350231743Sgibbs * o Query virtual device o Query backend device identification 351231743Sgibbs * properties. data. 352231743Sgibbs * o Setup OS device instance. o Open and validate backend device. 353231743Sgibbs * o Publish backend features and 354231743Sgibbs * transport parameters. 355231743Sgibbs * | 356231743Sgibbs * | 357231743Sgibbs * V 358231743Sgibbs * XenbusStateInitWait 359231743Sgibbs * 360231743Sgibbs * o Query backend features and 361231743Sgibbs * transport parameters. 362231743Sgibbs * o Allocate and initialize the 363231743Sgibbs * request ring. 364231743Sgibbs * o Publish transport parameters 365231743Sgibbs * that will be in effect during 366231743Sgibbs * this connection. 367231743Sgibbs * | 368231743Sgibbs * | 369231743Sgibbs * V 370231743Sgibbs * XenbusStateInitialised 371231743Sgibbs * 372231743Sgibbs * o Query frontend transport parameters. 373231743Sgibbs * o Connect to the request ring and 374231743Sgibbs * event channel. 375231743Sgibbs * o Publish backend device properties. 376231743Sgibbs * | 377231743Sgibbs * | 378231743Sgibbs * V 379231743Sgibbs * XenbusStateConnected 380231743Sgibbs * 381231743Sgibbs * o Query backend device properties. 382231743Sgibbs * o Finalize OS virtual device 383231743Sgibbs * instance. 384231743Sgibbs * | 385231743Sgibbs * | 386231743Sgibbs * V 387231743Sgibbs * XenbusStateConnected 388231743Sgibbs * 389231743Sgibbs * Note: Drivers that do not support any optional features, or the negotiation 390231743Sgibbs * of transport parameters, can skip certain states in the state machine: 391231743Sgibbs * 392231743Sgibbs * o A frontend may transition to XenbusStateInitialised without 393231743Sgibbs * waiting for the backend to enter XenbusStateInitWait. In this 394231743Sgibbs * case, default transport parameters are in effect and any 395231743Sgibbs * transport parameters published by the frontend must contain 396231743Sgibbs * their default values. 397231743Sgibbs * 398231743Sgibbs * o A backend may transition to XenbusStateInitialised, bypassing 399231743Sgibbs * XenbusStateInitWait, without waiting for the frontend to first 400231743Sgibbs * enter the XenbusStateInitialised state. In this case, default 401231743Sgibbs * transport parameters are in effect and any transport parameters 402231743Sgibbs * published by the backend must contain their default values. 403231743Sgibbs * 404231743Sgibbs * Drivers that support optional features and/or transport parameter 405231743Sgibbs * negotiation must tolerate these additional state transition paths. 406231743Sgibbs * In general this means performing the work of any skipped state 407231743Sgibbs * transition, if it has not already been performed, in addition to the 408231743Sgibbs * work associated with entry into the current state. 409231743Sgibbs */ 410231743Sgibbs 411231743Sgibbs/* 412181624Skmacy * REQUEST CODES. 413181624Skmacy */ 414181624Skmacy#define BLKIF_OP_READ 0 415181624Skmacy#define BLKIF_OP_WRITE 1 416181624Skmacy/* 417231743Sgibbs * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER 418231743Sgibbs * operation code ("barrier request") must be completed prior to the 419231743Sgibbs * execution of the barrier request. All writes issued after the barrier 420231743Sgibbs * request must not execute until after the completion of the barrier request. 421231743Sgibbs * 422231743Sgibbs * Optional. See "feature-barrier" XenBus node documentation above. 423181624Skmacy */ 424181624Skmacy#define BLKIF_OP_WRITE_BARRIER 2 425183375Skmacy/* 426231743Sgibbs * Commit any uncommitted contents of the backing device's volatile cache 427231743Sgibbs * to stable storage. 428231743Sgibbs * 429231743Sgibbs * Optional. See "feature-flush-cache" XenBus node documentation above. 430183375Skmacy */ 431183375Skmacy#define BLKIF_OP_FLUSH_DISKCACHE 3 432231743Sgibbs/* 433231743Sgibbs * Used in SLES sources for device specific command packet 434231743Sgibbs * contained within the request. Reserved for that purpose. 435231743Sgibbs */ 436231743Sgibbs#define BLKIF_OP_RESERVED_1 4 437231743Sgibbs/* 438231743Sgibbs * Indicate to the backend device that a region of storage is no longer in 439231743Sgibbs * use, and may be discarded at any time without impact to the client. If 440231743Sgibbs * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the 441231743Sgibbs * discarded region on the device must be rendered unrecoverable before the 442231743Sgibbs * command returns. 443231743Sgibbs * 444232308Sgibbs * This operation is analogous to performing a trim (ATA) or unmap (SCSI), 445231743Sgibbs * command on a native device. 446231743Sgibbs * 447231743Sgibbs * More information about trim/unmap operations can be found at: 448231743Sgibbs * http://t13.org/Documents/UploadedDocuments/docs2008/ 449231743Sgibbs * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc 450231743Sgibbs * http://www.seagate.com/staticfiles/support/disc/manuals/ 451231743Sgibbs * Interface%20manuals/100293068c.pdf 452231743Sgibbs * 453231743Sgibbs * Optional. See "feature-discard", "discard-alignment", 454231743Sgibbs * "discard-granularity", and "discard-secure" in the XenBus node 455231743Sgibbs * documentation above. 456231743Sgibbs */ 457231743Sgibbs#define BLKIF_OP_DISCARD 5 458181624Skmacy 459181624Skmacy/* 460214077Sgibbs * Maximum scatter/gather segments associated with a request header block. 461231743Sgibbs * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE. 462231743Sgibbs * NB. This could be 12 if the ring indexes weren't stored in the same page. 463181624Skmacy */ 464214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 11 465181624Skmacy 466214077Sgibbs/* 467214077Sgibbs * Maximum scatter/gather segments associated with a segment block. 468214077Sgibbs */ 469214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK 14 470214077Sgibbs 471214077Sgibbs/* 472214077Sgibbs * Maximum scatter/gather segments per request (header + segment blocks). 473214077Sgibbs */ 474214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_REQUEST 255 475214077Sgibbs 476231743Sgibbs/* 477231743Sgibbs * NB. first_sect and last_sect in blkif_request_segment, as well as 478231743Sgibbs * sector_number in blkif_request, are always expressed in 512-byte units. 479231743Sgibbs * However they must be properly aligned to the real sector size of the 480231743Sgibbs * physical disk, which is reported in the "sector-size" node in the backend 481231743Sgibbs * xenbus info. Also the xenbus "sectors" node is expressed in 512-byte units. 482231743Sgibbs */ 483181624Skmacystruct blkif_request_segment { 484181624Skmacy grant_ref_t gref; /* reference to I/O buffer frame */ 485181624Skmacy /* @first_sect: first sector in frame to transfer (inclusive). */ 486181624Skmacy /* @last_sect: last sector in frame to transfer (inclusive). */ 487181624Skmacy uint8_t first_sect, last_sect; 488181624Skmacy}; 489214077Sgibbstypedef struct blkif_request_segment blkif_request_segment_t; 490181624Skmacy 491231743Sgibbs/* 492231743Sgibbs * Starting ring element for any I/O request. 493231743Sgibbs * 494231743Sgibbs * One or more segment blocks can be inserted into the request ring 495231743Sgibbs * just after a blkif_request_t, allowing requests to operate on 496231743Sgibbs * up to BLKIF_MAX_SEGMENTS_PER_REQUEST. 497231743Sgibbs * 498231743Sgibbs * BLKIF_SEGS_TO_BLOCKS() can be used on blkif_requst.nr_segments 499231743Sgibbs * to determine the number of contiguous ring entries associated 500231743Sgibbs * with this request. 501231743Sgibbs * 502231743Sgibbs * Note: Due to the way Xen request rings operate, the producer and 503231743Sgibbs * consumer indices of the ring must be incremented by the 504231743Sgibbs * BLKIF_SEGS_TO_BLOCKS() value of the associated request. 505231743Sgibbs * (e.g. a response to a 3 ring entry request must also consume 506231743Sgibbs * 3 entries in the ring, even though only the first ring entry 507231743Sgibbs * in the response has any data.) 508231743Sgibbs */ 509181624Skmacystruct blkif_request { 510181624Skmacy uint8_t operation; /* BLKIF_OP_??? */ 511181624Skmacy uint8_t nr_segments; /* number of segments */ 512181624Skmacy blkif_vdev_t handle; /* only for read/write requests */ 513181624Skmacy uint64_t id; /* private guest value, echoed in resp */ 514181624Skmacy blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 515231743Sgibbs blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK]; 516181624Skmacy}; 517181624Skmacytypedef struct blkif_request blkif_request_t; 518181624Skmacy 519231743Sgibbs/* 520231743Sgibbs * A segment block is a ring request structure that contains only 521231743Sgibbs * segment data. 522231743Sgibbs * 523231743Sgibbs * sizeof(struct blkif_segment_block) <= sizeof(struct blkif_request) 524231743Sgibbs */ 525231743Sgibbsstruct blkif_segment_block { 526231743Sgibbs blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK]; 527231743Sgibbs}; 528231743Sgibbstypedef struct blkif_segment_block blkif_segment_block_t; 529231743Sgibbs 530231743Sgibbs/* 531231743Sgibbs * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD 532231743Sgibbs * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request) 533231743Sgibbs */ 534231743Sgibbsstruct blkif_request_discard { 535231743Sgibbs uint8_t operation; /* BLKIF_OP_DISCARD */ 536231743Sgibbs uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */ 537231743Sgibbs#define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */ 538231743Sgibbs blkif_vdev_t handle; /* same as for read/write requests */ 539231743Sgibbs uint64_t id; /* private guest value, echoed in resp */ 540231743Sgibbs blkif_sector_t sector_number;/* start sector idx on disk */ 541231743Sgibbs uint64_t nr_sectors; /* number of contiguous sectors to discard*/ 542231743Sgibbs}; 543231743Sgibbstypedef struct blkif_request_discard blkif_request_discard_t; 544231743Sgibbs 545181624Skmacystruct blkif_response { 546181624Skmacy uint64_t id; /* copied from request */ 547181624Skmacy uint8_t operation; /* copied from request */ 548181624Skmacy int16_t status; /* BLKIF_RSP_??? */ 549181624Skmacy}; 550181624Skmacytypedef struct blkif_response blkif_response_t; 551181624Skmacy 552181624Skmacy/* 553181624Skmacy * STATUS RETURN CODES. 554181624Skmacy */ 555181624Skmacy /* Operation not supported (only happens on barrier writes). */ 556181624Skmacy#define BLKIF_RSP_EOPNOTSUPP -2 557181624Skmacy /* Operation failed for some unspecified reason (-EIO). */ 558181624Skmacy#define BLKIF_RSP_ERROR -1 559181624Skmacy /* Operation completed successfully. */ 560181624Skmacy#define BLKIF_RSP_OKAY 0 561181624Skmacy 562181624Skmacy/* 563181624Skmacy * Generate blkif ring structures and types. 564181624Skmacy */ 565181624SkmacyDEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); 566181624Skmacy 567231743Sgibbs/* 568231743Sgibbs * Index to, and treat as a segment block, an entry in the ring. 569231743Sgibbs */ 570231743Sgibbs#define BLKRING_GET_SEG_BLOCK(_r, _idx) \ 571231743Sgibbs (((blkif_segment_block_t *)RING_GET_REQUEST(_r, _idx))->seg) 572214077Sgibbs 573214077Sgibbs/* 574214077Sgibbs * The number of ring request blocks required to handle an I/O 575214077Sgibbs * request containing _segs segments. 576214077Sgibbs */ 577231743Sgibbs#define BLKIF_SEGS_TO_BLOCKS(_segs) \ 578231743Sgibbs ((((_segs - BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK) \ 579231743Sgibbs + (BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK - 1)) \ 580231743Sgibbs / BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK) + /*header_block*/1) 581214077Sgibbs 582231743Sgibbs#define VDISK_CDROM 0x1 583231743Sgibbs#define VDISK_REMOVABLE 0x2 584231743Sgibbs#define VDISK_READONLY 0x4 585231743Sgibbs 586181624Skmacy#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ 587181624Skmacy 588181624Skmacy/* 589181624Skmacy * Local variables: 590181624Skmacy * mode: C 591181624Skmacy * c-set-style: "BSD" 592181624Skmacy * c-basic-offset: 4 593181624Skmacy * tab-width: 4 594181624Skmacy * indent-tabs-mode: nil 595181624Skmacy * End: 596181624Skmacy */ 597