blkif.h revision 181624
1181624Skmacy/******************************************************************************
2181624Skmacy * blkif.h
3181624Skmacy *
4181624Skmacy * Unified block-device I/O interface for Xen guest OSes.
5181624Skmacy *
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
25181624Skmacy */
26181624Skmacy
27181624Skmacy#ifndef __XEN_PUBLIC_IO_BLKIF_H__
28181624Skmacy#define __XEN_PUBLIC_IO_BLKIF_H__
29181624Skmacy
30181624Skmacy#include <xen/interface/io/ring.h>
31181624Skmacy#include <xen/interface/grant_table.h>
32181624Skmacy
33181624Skmacy/*
34181624Skmacy * Front->back notifications: When enqueuing a new request, sending a
35181624Skmacy * notification can be made conditional on req_event (i.e., the generic
36181624Skmacy * hold-off mechanism provided by the ring macros). Backends must set
37181624Skmacy * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
38181624Skmacy *
39181624Skmacy * Back->front notifications: When enqueuing a new response, sending a
40181624Skmacy * notification can be made conditional on rsp_event (i.e., the generic
41181624Skmacy * hold-off mechanism provided by the ring macros). Frontends must set
42181624Skmacy * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
43181624Skmacy */
44181624Skmacy
45181624Skmacy#ifndef blkif_vdev_t
46181624Skmacy#define blkif_vdev_t   uint16_t
47181624Skmacy#endif
48181624Skmacy#define blkif_sector_t uint64_t
49181624Skmacy
50181624Skmacy/*
51181624Skmacy * REQUEST CODES.
52181624Skmacy */
53181624Skmacy#define BLKIF_OP_READ              0
54181624Skmacy#define BLKIF_OP_WRITE             1
55181624Skmacy/*
56181624Skmacy * Recognised only if "feature-barrier" is present in backend xenbus info.
57181624Skmacy * The "feature_barrier" node contains a boolean indicating whether barrier
58181624Skmacy * requests are likely to succeed or fail. Either way, a barrier request
59181624Skmacy * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
60181624Skmacy * the underlying block-device hardware. The boolean simply indicates whether
61181624Skmacy * or not it is worthwhile for the frontend to attempt barrier requests.
62181624Skmacy * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*
63181624Skmacy * create the "feature-barrier" node!
64181624Skmacy */
65181624Skmacy#define BLKIF_OP_WRITE_BARRIER     2
66181624Skmacy
67181624Skmacy/*
68181624Skmacy * Maximum scatter/gather segments per request.
69181624Skmacy * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
70181624Skmacy * NB. This could be 12 if the ring indexes weren't stored in the same page.
71181624Skmacy */
72181624Skmacy#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
73181624Skmacy
74181624Skmacystruct blkif_request_segment {
75181624Skmacy    grant_ref_t gref;        /* reference to I/O buffer frame        */
76181624Skmacy    /* @first_sect: first sector in frame to transfer (inclusive).   */
77181624Skmacy    /* @last_sect: last sector in frame to transfer (inclusive).     */
78181624Skmacy    uint8_t     first_sect, last_sect;
79181624Skmacy};
80181624Skmacy
81181624Skmacystruct blkif_request {
82181624Skmacy    uint8_t        operation;    /* BLKIF_OP_???                         */
83181624Skmacy    uint8_t        nr_segments;  /* number of segments                   */
84181624Skmacy    blkif_vdev_t   handle;       /* only for read/write requests         */
85181624Skmacy    uint64_t       id;           /* private guest value, echoed in resp  */
86181624Skmacy    blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
87181624Skmacy    struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
88181624Skmacy};
89181624Skmacytypedef struct blkif_request blkif_request_t;
90181624Skmacy
91181624Skmacystruct blkif_response {
92181624Skmacy    uint64_t        id;              /* copied from request */
93181624Skmacy    uint8_t         operation;       /* copied from request */
94181624Skmacy    int16_t         status;          /* BLKIF_RSP_???       */
95181624Skmacy};
96181624Skmacytypedef struct blkif_response blkif_response_t;
97181624Skmacy
98181624Skmacy/*
99181624Skmacy * STATUS RETURN CODES.
100181624Skmacy */
101181624Skmacy /* Operation not supported (only happens on barrier writes). */
102181624Skmacy#define BLKIF_RSP_EOPNOTSUPP  -2
103181624Skmacy /* Operation failed for some unspecified reason (-EIO). */
104181624Skmacy#define BLKIF_RSP_ERROR       -1
105181624Skmacy /* Operation completed successfully. */
106181624Skmacy#define BLKIF_RSP_OKAY         0
107181624Skmacy
108181624Skmacy/*
109181624Skmacy * Generate blkif ring structures and types.
110181624Skmacy */
111181624Skmacy
112181624SkmacyDEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
113181624Skmacy
114181624Skmacy#define VDISK_CDROM        0x1
115181624Skmacy#define VDISK_REMOVABLE    0x2
116181624Skmacy#define VDISK_READONLY     0x4
117181624Skmacy
118181624Skmacy#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
119181624Skmacy
120181624Skmacy/*
121181624Skmacy * Local variables:
122181624Skmacy * mode: C
123181624Skmacy * c-set-style: "BSD"
124181624Skmacy * c-basic-offset: 4
125181624Skmacy * tab-width: 4
126181624Skmacy * indent-tabs-mode: nil
127181624Skmacy * End:
128181624Skmacy */
129