xref: /onnv-gate/usr/src/uts/common/xen/public/io/blkif.h (revision 5084:7d838c5c0eed)
1*5084Sjohnlev /******************************************************************************
2*5084Sjohnlev  * blkif.h
3*5084Sjohnlev  *
4*5084Sjohnlev  * Unified block-device I/O interface for Xen guest OSes.
5*5084Sjohnlev  *
6*5084Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*5084Sjohnlev  * of this software and associated documentation files (the "Software"), to
8*5084Sjohnlev  * deal in the Software without restriction, including without limitation the
9*5084Sjohnlev  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*5084Sjohnlev  * sell copies of the Software, and to permit persons to whom the Software is
11*5084Sjohnlev  * furnished to do so, subject to the following conditions:
12*5084Sjohnlev  *
13*5084Sjohnlev  * The above copyright notice and this permission notice shall be included in
14*5084Sjohnlev  * all copies or substantial portions of the Software.
15*5084Sjohnlev  *
16*5084Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*5084Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*5084Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*5084Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*5084Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*5084Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*5084Sjohnlev  * DEALINGS IN THE SOFTWARE.
23*5084Sjohnlev  *
24*5084Sjohnlev  * Copyright (c) 2003-2004, Keir Fraser
25*5084Sjohnlev  */
26*5084Sjohnlev 
27*5084Sjohnlev #ifndef __XEN_PUBLIC_IO_BLKIF_H__
28*5084Sjohnlev #define __XEN_PUBLIC_IO_BLKIF_H__
29*5084Sjohnlev 
30*5084Sjohnlev #include "ring.h"
31*5084Sjohnlev #include "../grant_table.h"
32*5084Sjohnlev 
33*5084Sjohnlev /*
34*5084Sjohnlev  * Front->back notifications: When enqueuing a new request, sending a
35*5084Sjohnlev  * notification can be made conditional on req_event (i.e., the generic
36*5084Sjohnlev  * hold-off mechanism provided by the ring macros). Backends must set
37*5084Sjohnlev  * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
38*5084Sjohnlev  *
39*5084Sjohnlev  * Back->front notifications: When enqueuing a new response, sending a
40*5084Sjohnlev  * notification can be made conditional on rsp_event (i.e., the generic
41*5084Sjohnlev  * hold-off mechanism provided by the ring macros). Frontends must set
42*5084Sjohnlev  * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
43*5084Sjohnlev  */
44*5084Sjohnlev 
45*5084Sjohnlev #ifndef blkif_vdev_t
46*5084Sjohnlev #define blkif_vdev_t   uint16_t
47*5084Sjohnlev #endif
48*5084Sjohnlev #define blkif_sector_t uint64_t
49*5084Sjohnlev 
50*5084Sjohnlev /*
51*5084Sjohnlev  * REQUEST CODES.
52*5084Sjohnlev  */
53*5084Sjohnlev #define BLKIF_OP_READ              0
54*5084Sjohnlev #define BLKIF_OP_WRITE             1
55*5084Sjohnlev /*
56*5084Sjohnlev  * Recognised only if "feature-barrier" is present in backend xenbus info.
57*5084Sjohnlev  * The "feature_barrier" node contains a boolean indicating whether barrier
58*5084Sjohnlev  * requests or disk cache flush requests are likely to succeed or fail.
59*5084Sjohnlev  * Either way, a barrier request or a disk cache flush request
60*5084Sjohnlev  * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
61*5084Sjohnlev  * the underlying block-device hardware. The boolean simply indicates whether
62*5084Sjohnlev  * or not it is worthwhile for the frontend to attempt barrier/flush requests.
63*5084Sjohnlev  * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*
64*5084Sjohnlev  * create the "feature-barrier" node!
65*5084Sjohnlev  */
66*5084Sjohnlev #define BLKIF_OP_WRITE_BARRIER     2
67*5084Sjohnlev #define BLKIF_OP_FLUSH_DISKCACHE   3
68*5084Sjohnlev 
69*5084Sjohnlev /*
70*5084Sjohnlev  * Maximum scatter/gather segments per request.
71*5084Sjohnlev  * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
72*5084Sjohnlev  * NB. This could be 12 if the ring indexes weren't stored in the same page.
73*5084Sjohnlev  */
74*5084Sjohnlev #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
75*5084Sjohnlev 
76*5084Sjohnlev struct blkif_request {
77*5084Sjohnlev     uint8_t        operation;    /* BLKIF_OP_???                         */
78*5084Sjohnlev     uint8_t        nr_segments;  /* number of segments                   */
79*5084Sjohnlev     blkif_vdev_t   handle;       /* only for read/write requests         */
80*5084Sjohnlev     uint64_t       id;           /* private guest value, echoed in resp  */
81*5084Sjohnlev     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
82*5084Sjohnlev     struct blkif_request_segment {
83*5084Sjohnlev         grant_ref_t gref;        /* reference to I/O buffer frame        */
84*5084Sjohnlev         /* @first_sect: first sector in frame to transfer (inclusive).   */
85*5084Sjohnlev         /* @last_sect: last sector in frame to transfer (inclusive).     */
86*5084Sjohnlev         uint8_t     first_sect, last_sect;
87*5084Sjohnlev     } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
88*5084Sjohnlev };
89*5084Sjohnlev typedef struct blkif_request blkif_request_t;
90*5084Sjohnlev 
91*5084Sjohnlev struct blkif_response {
92*5084Sjohnlev     uint64_t        id;              /* copied from request */
93*5084Sjohnlev     uint8_t         operation;       /* copied from request */
94*5084Sjohnlev     int16_t         status;          /* BLKIF_RSP_???       */
95*5084Sjohnlev };
96*5084Sjohnlev typedef struct blkif_response blkif_response_t;
97*5084Sjohnlev 
98*5084Sjohnlev /*
99*5084Sjohnlev  * STATUS RETURN CODES.
100*5084Sjohnlev  */
101*5084Sjohnlev  /* Operation not supported (only happens on barrier writes). */
102*5084Sjohnlev #define BLKIF_RSP_EOPNOTSUPP  -2
103*5084Sjohnlev  /* Operation failed for some unspecified reason (-EIO). */
104*5084Sjohnlev #define BLKIF_RSP_ERROR       -1
105*5084Sjohnlev  /* Operation completed successfully. */
106*5084Sjohnlev #define BLKIF_RSP_OKAY         0
107*5084Sjohnlev 
108*5084Sjohnlev /*
109*5084Sjohnlev  * Generate blkif ring structures and types.
110*5084Sjohnlev  */
111*5084Sjohnlev 
112*5084Sjohnlev DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
113*5084Sjohnlev 
114*5084Sjohnlev #define VDISK_CDROM        0x1
115*5084Sjohnlev #define VDISK_REMOVABLE    0x2
116*5084Sjohnlev #define VDISK_READONLY     0x4
117*5084Sjohnlev 
118*5084Sjohnlev #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
119*5084Sjohnlev 
120*5084Sjohnlev /*
121*5084Sjohnlev  * Local variables:
122*5084Sjohnlev  * mode: C
123*5084Sjohnlev  * c-set-style: "BSD"
124*5084Sjohnlev  * c-basic-offset: 4
125*5084Sjohnlev  * tab-width: 4
126*5084Sjohnlev  * indent-tabs-mode: nil
127*5084Sjohnlev  * End:
128*5084Sjohnlev  */
129