15084Sjohnlev /****************************************************************************** 25084Sjohnlev * blkif.h 35084Sjohnlev * 45084Sjohnlev * Unified block-device I/O interface for Xen guest OSes. 55084Sjohnlev * 65084Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 75084Sjohnlev * of this software and associated documentation files (the "Software"), to 85084Sjohnlev * deal in the Software without restriction, including without limitation the 95084Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105084Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 115084Sjohnlev * furnished to do so, subject to the following conditions: 125084Sjohnlev * 135084Sjohnlev * The above copyright notice and this permission notice shall be included in 145084Sjohnlev * all copies or substantial portions of the Software. 155084Sjohnlev * 165084Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175084Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185084Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 195084Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 205084Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 215084Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 225084Sjohnlev * DEALINGS IN THE SOFTWARE. 235084Sjohnlev * 245084Sjohnlev * Copyright (c) 2003-2004, Keir Fraser 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev #ifndef __XEN_PUBLIC_IO_BLKIF_H__ 285084Sjohnlev #define __XEN_PUBLIC_IO_BLKIF_H__ 295084Sjohnlev 305084Sjohnlev #include "ring.h" 315084Sjohnlev #include "../grant_table.h" 325084Sjohnlev 335084Sjohnlev /* 345084Sjohnlev * Front->back notifications: When enqueuing a new request, sending a 355084Sjohnlev * notification can be made conditional on req_event (i.e., the generic 365084Sjohnlev * hold-off mechanism provided by the ring macros). Backends must set 375084Sjohnlev * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()). 385084Sjohnlev * 395084Sjohnlev * Back->front notifications: When enqueuing a new response, sending a 405084Sjohnlev * notification can be made conditional on rsp_event (i.e., the generic 415084Sjohnlev * hold-off mechanism provided by the ring macros). Frontends must set 425084Sjohnlev * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()). 435084Sjohnlev */ 445084Sjohnlev 455084Sjohnlev #ifndef blkif_vdev_t 465084Sjohnlev #define blkif_vdev_t uint16_t 475084Sjohnlev #endif 485084Sjohnlev #define blkif_sector_t uint64_t 495084Sjohnlev 505084Sjohnlev /* 515084Sjohnlev * REQUEST CODES. 525084Sjohnlev */ 535084Sjohnlev #define BLKIF_OP_READ 0 545084Sjohnlev #define BLKIF_OP_WRITE 1 555084Sjohnlev /* 565084Sjohnlev * Recognised only if "feature-barrier" is present in backend xenbus info. 5710175SStuart.Maybee@Sun.COM * The "feature-barrier" node contains a boolean indicating whether barrier 5810175SStuart.Maybee@Sun.COM * requests are likely to succeed or fail. Either way, a barrier request 595084Sjohnlev * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by 605084Sjohnlev * the underlying block-device hardware. The boolean simply indicates whether 6110175SStuart.Maybee@Sun.COM * or not it is worthwhile for the frontend to attempt barrier requests. 625084Sjohnlev * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not* 635084Sjohnlev * create the "feature-barrier" node! 645084Sjohnlev */ 655084Sjohnlev #define BLKIF_OP_WRITE_BARRIER 2 6610175SStuart.Maybee@Sun.COM /* 6710175SStuart.Maybee@Sun.COM * Recognised if "feature-flush-cache" is present in backend xenbus 6810175SStuart.Maybee@Sun.COM * info. A flush will ask the underlying storage hardware to flush its 6910175SStuart.Maybee@Sun.COM * non-volatile caches as appropriate. The "feature-flush-cache" node 7010175SStuart.Maybee@Sun.COM * contains a boolean indicating whether flush requests are likely to 7110175SStuart.Maybee@Sun.COM * succeed or fail. Either way, a flush request may fail at any time 7210175SStuart.Maybee@Sun.COM * with BLKIF_RSP_EOPNOTSUPP if it is unsupported by the underlying 7310175SStuart.Maybee@Sun.COM * block-device hardware. The boolean simply indicates whether or not it 7410175SStuart.Maybee@Sun.COM * is worthwhile for the frontend to attempt flushes. If a backend does 7510175SStuart.Maybee@Sun.COM * not recognise BLKIF_OP_WRITE_FLUSH_CACHE, it should *not* create the 7610175SStuart.Maybee@Sun.COM * "feature-flush-cache" node! 7710175SStuart.Maybee@Sun.COM */ 785084Sjohnlev #define BLKIF_OP_FLUSH_DISKCACHE 3 795084Sjohnlev 805084Sjohnlev /* 815084Sjohnlev * Maximum scatter/gather segments per request. 825084Sjohnlev * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE. 835084Sjohnlev * NB. This could be 12 if the ring indexes weren't stored in the same page. 845084Sjohnlev */ 855084Sjohnlev #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11 865084Sjohnlev 87*11120SMark.Johnson@Sun.COM /* 88*11120SMark.Johnson@Sun.COM * NB. first_sect and last_sect in blkif_request_segment, as well as 89*11120SMark.Johnson@Sun.COM * sector_number in blkif_request, are always expressed in 512-byte units. 90*11120SMark.Johnson@Sun.COM * However they must be properly aligned to the real sector size of the 91*11120SMark.Johnson@Sun.COM * physical disk, which is reported in the "sector-size" node in the backend 92*11120SMark.Johnson@Sun.COM * xenbus info. Also the xenbus "sectors" node is expressed in 512-byte units. 93*11120SMark.Johnson@Sun.COM */ 946144Srab struct blkif_request_segment { 956144Srab grant_ref_t gref; /* reference to I/O buffer frame */ 966144Srab /* @first_sect: first sector in frame to transfer (inclusive). */ 976144Srab /* @last_sect: last sector in frame to transfer (inclusive). */ 986144Srab uint8_t first_sect, last_sect; 996144Srab }; 1006144Srab 1015084Sjohnlev struct blkif_request { 1025084Sjohnlev uint8_t operation; /* BLKIF_OP_??? */ 1035084Sjohnlev uint8_t nr_segments; /* number of segments */ 1045084Sjohnlev blkif_vdev_t handle; /* only for read/write requests */ 1055084Sjohnlev uint64_t id; /* private guest value, echoed in resp */ 1065084Sjohnlev blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 1076144Srab struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 1085084Sjohnlev }; 1095084Sjohnlev typedef struct blkif_request blkif_request_t; 1105084Sjohnlev 1115084Sjohnlev struct blkif_response { 1125084Sjohnlev uint64_t id; /* copied from request */ 1135084Sjohnlev uint8_t operation; /* copied from request */ 1145084Sjohnlev int16_t status; /* BLKIF_RSP_??? */ 1155084Sjohnlev }; 1165084Sjohnlev typedef struct blkif_response blkif_response_t; 1175084Sjohnlev 1185084Sjohnlev /* 1195084Sjohnlev * STATUS RETURN CODES. 1205084Sjohnlev */ 1215084Sjohnlev /* Operation not supported (only happens on barrier writes). */ 1225084Sjohnlev #define BLKIF_RSP_EOPNOTSUPP -2 1235084Sjohnlev /* Operation failed for some unspecified reason (-EIO). */ 1245084Sjohnlev #define BLKIF_RSP_ERROR -1 1255084Sjohnlev /* Operation completed successfully. */ 1265084Sjohnlev #define BLKIF_RSP_OKAY 0 1275084Sjohnlev 1285084Sjohnlev /* 1295084Sjohnlev * Generate blkif ring structures and types. 1305084Sjohnlev */ 1315084Sjohnlev 1325084Sjohnlev DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); 1335084Sjohnlev 1345084Sjohnlev #define VDISK_CDROM 0x1 1355084Sjohnlev #define VDISK_REMOVABLE 0x2 1365084Sjohnlev #define VDISK_READONLY 0x4 1375084Sjohnlev 1385084Sjohnlev #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ 1395084Sjohnlev 1405084Sjohnlev /* 1415084Sjohnlev * Local variables: 1425084Sjohnlev * mode: C 1435084Sjohnlev * c-set-style: "BSD" 1445084Sjohnlev * c-basic-offset: 4 1455084Sjohnlev * tab-width: 4 1465084Sjohnlev * indent-tabs-mode: nil 1475084Sjohnlev * End: 1485084Sjohnlev */ 149