xref: /qemu/include/hw/xen/interface/io/blkif.h (revision a3434a2d56aee3018f4a0f55c7e0f0cda11f3d9e)
1*a3434a2dSAnthony PERARD /******************************************************************************
2*a3434a2dSAnthony PERARD  * blkif.h
3*a3434a2dSAnthony PERARD  *
4*a3434a2dSAnthony PERARD  * Unified block-device I/O interface for Xen guest OSes.
5*a3434a2dSAnthony PERARD  *
6*a3434a2dSAnthony PERARD  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*a3434a2dSAnthony PERARD  * of this software and associated documentation files (the "Software"), to
8*a3434a2dSAnthony PERARD  * deal in the Software without restriction, including without limitation the
9*a3434a2dSAnthony PERARD  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*a3434a2dSAnthony PERARD  * sell copies of the Software, and to permit persons to whom the Software is
11*a3434a2dSAnthony PERARD  * furnished to do so, subject to the following conditions:
12*a3434a2dSAnthony PERARD  *
13*a3434a2dSAnthony PERARD  * The above copyright notice and this permission notice shall be included in
14*a3434a2dSAnthony PERARD  * all copies or substantial portions of the Software.
15*a3434a2dSAnthony PERARD  *
16*a3434a2dSAnthony PERARD  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*a3434a2dSAnthony PERARD  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*a3434a2dSAnthony PERARD  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*a3434a2dSAnthony PERARD  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*a3434a2dSAnthony PERARD  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*a3434a2dSAnthony PERARD  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*a3434a2dSAnthony PERARD  * DEALINGS IN THE SOFTWARE.
23*a3434a2dSAnthony PERARD  *
24*a3434a2dSAnthony PERARD  * Copyright (c) 2003-2004, Keir Fraser
25*a3434a2dSAnthony PERARD  * Copyright (c) 2012, Spectra Logic Corporation
26*a3434a2dSAnthony PERARD  */
27*a3434a2dSAnthony PERARD 
28*a3434a2dSAnthony PERARD #ifndef __XEN_PUBLIC_IO_BLKIF_H__
29*a3434a2dSAnthony PERARD #define __XEN_PUBLIC_IO_BLKIF_H__
30*a3434a2dSAnthony PERARD 
31*a3434a2dSAnthony PERARD #include "ring.h"
32*a3434a2dSAnthony PERARD #include "../grant_table.h"
33*a3434a2dSAnthony PERARD 
34*a3434a2dSAnthony PERARD /*
35*a3434a2dSAnthony PERARD  * Front->back notifications: When enqueuing a new request, sending a
36*a3434a2dSAnthony PERARD  * notification can be made conditional on req_event (i.e., the generic
37*a3434a2dSAnthony PERARD  * hold-off mechanism provided by the ring macros). Backends must set
38*a3434a2dSAnthony PERARD  * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
39*a3434a2dSAnthony PERARD  *
40*a3434a2dSAnthony PERARD  * Back->front notifications: When enqueuing a new response, sending a
41*a3434a2dSAnthony PERARD  * notification can be made conditional on rsp_event (i.e., the generic
42*a3434a2dSAnthony PERARD  * hold-off mechanism provided by the ring macros). Frontends must set
43*a3434a2dSAnthony PERARD  * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
44*a3434a2dSAnthony PERARD  */
45*a3434a2dSAnthony PERARD 
46*a3434a2dSAnthony PERARD #ifndef blkif_vdev_t
47*a3434a2dSAnthony PERARD #define blkif_vdev_t   uint16_t
48*a3434a2dSAnthony PERARD #endif
49*a3434a2dSAnthony PERARD #define blkif_sector_t uint64_t
50*a3434a2dSAnthony PERARD 
51*a3434a2dSAnthony PERARD /*
52*a3434a2dSAnthony PERARD  * Feature and Parameter Negotiation
53*a3434a2dSAnthony PERARD  * =================================
54*a3434a2dSAnthony PERARD  * The two halves of a Xen block driver utilize nodes within the XenStore to
55*a3434a2dSAnthony PERARD  * communicate capabilities and to negotiate operating parameters.  This
56*a3434a2dSAnthony PERARD  * section enumerates these nodes which reside in the respective front and
57*a3434a2dSAnthony PERARD  * backend portions of the XenStore, following the XenBus convention.
58*a3434a2dSAnthony PERARD  *
59*a3434a2dSAnthony PERARD  * All data in the XenStore is stored as strings.  Nodes specifying numeric
60*a3434a2dSAnthony PERARD  * values are encoded in decimal.  Integer value ranges listed below are
61*a3434a2dSAnthony PERARD  * expressed as fixed sized integer types capable of storing the conversion
62*a3434a2dSAnthony PERARD  * of a properly formated node string, without loss of information.
63*a3434a2dSAnthony PERARD  *
64*a3434a2dSAnthony PERARD  * Any specified default value is in effect if the corresponding XenBus node
65*a3434a2dSAnthony PERARD  * is not present in the XenStore.
66*a3434a2dSAnthony PERARD  *
67*a3434a2dSAnthony PERARD  * XenStore nodes in sections marked "PRIVATE" are solely for use by the
68*a3434a2dSAnthony PERARD  * driver side whose XenBus tree contains them.
69*a3434a2dSAnthony PERARD  *
70*a3434a2dSAnthony PERARD  * XenStore nodes marked "DEPRECATED" in their notes section should only be
71*a3434a2dSAnthony PERARD  * used to provide interoperability with legacy implementations.
72*a3434a2dSAnthony PERARD  *
73*a3434a2dSAnthony PERARD  * See the XenBus state transition diagram below for details on when XenBus
74*a3434a2dSAnthony PERARD  * nodes must be published and when they can be queried.
75*a3434a2dSAnthony PERARD  *
76*a3434a2dSAnthony PERARD  *****************************************************************************
77*a3434a2dSAnthony PERARD  *                            Backend XenBus Nodes
78*a3434a2dSAnthony PERARD  *****************************************************************************
79*a3434a2dSAnthony PERARD  *
80*a3434a2dSAnthony PERARD  *------------------ Backend Device Identification (PRIVATE) ------------------
81*a3434a2dSAnthony PERARD  *
82*a3434a2dSAnthony PERARD  * mode
83*a3434a2dSAnthony PERARD  *      Values:         "r" (read only), "w" (writable)
84*a3434a2dSAnthony PERARD  *
85*a3434a2dSAnthony PERARD  *      The read or write access permissions to the backing store to be
86*a3434a2dSAnthony PERARD  *      granted to the frontend.
87*a3434a2dSAnthony PERARD  *
88*a3434a2dSAnthony PERARD  * params
89*a3434a2dSAnthony PERARD  *      Values:         string
90*a3434a2dSAnthony PERARD  *
91*a3434a2dSAnthony PERARD  *      A free formatted string providing sufficient information for the
92*a3434a2dSAnthony PERARD  *      hotplug script to attach the device and provide a suitable
93*a3434a2dSAnthony PERARD  *      handler (ie: a block device) for blkback to use.
94*a3434a2dSAnthony PERARD  *
95*a3434a2dSAnthony PERARD  * physical-device
96*a3434a2dSAnthony PERARD  *      Values:         "MAJOR:MINOR"
97*a3434a2dSAnthony PERARD  *      Notes: 11
98*a3434a2dSAnthony PERARD  *
99*a3434a2dSAnthony PERARD  *      MAJOR and MINOR are the major number and minor number of the
100*a3434a2dSAnthony PERARD  *      backing device respectively.
101*a3434a2dSAnthony PERARD  *
102*a3434a2dSAnthony PERARD  * physical-device-path
103*a3434a2dSAnthony PERARD  *      Values:         path string
104*a3434a2dSAnthony PERARD  *
105*a3434a2dSAnthony PERARD  *      A string that contains the absolute path to the disk image. On
106*a3434a2dSAnthony PERARD  *      NetBSD and Linux this is always a block device, while on FreeBSD
107*a3434a2dSAnthony PERARD  *      it can be either a block device or a regular file.
108*a3434a2dSAnthony PERARD  *
109*a3434a2dSAnthony PERARD  * type
110*a3434a2dSAnthony PERARD  *      Values:         "file", "phy", "tap"
111*a3434a2dSAnthony PERARD  *
112*a3434a2dSAnthony PERARD  *      The type of the backing device/object.
113*a3434a2dSAnthony PERARD  *
114*a3434a2dSAnthony PERARD  *
115*a3434a2dSAnthony PERARD  * direct-io-safe
116*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
117*a3434a2dSAnthony PERARD  *      Default Value:  0
118*a3434a2dSAnthony PERARD  *
119*a3434a2dSAnthony PERARD  *      The underlying storage is not affected by the direct IO memory
120*a3434a2dSAnthony PERARD  *      lifetime bug.  See:
121*a3434a2dSAnthony PERARD  *        http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
122*a3434a2dSAnthony PERARD  *
123*a3434a2dSAnthony PERARD  *      Therefore this option gives the backend permission to use
124*a3434a2dSAnthony PERARD  *      O_DIRECT, notwithstanding that bug.
125*a3434a2dSAnthony PERARD  *
126*a3434a2dSAnthony PERARD  *      That is, if this option is enabled, use of O_DIRECT is safe,
127*a3434a2dSAnthony PERARD  *      in circumstances where we would normally have avoided it as a
128*a3434a2dSAnthony PERARD  *      workaround for that bug.  This option is not relevant for all
129*a3434a2dSAnthony PERARD  *      backends, and even not necessarily supported for those for
130*a3434a2dSAnthony PERARD  *      which it is relevant.  A backend which knows that it is not
131*a3434a2dSAnthony PERARD  *      affected by the bug can ignore this option.
132*a3434a2dSAnthony PERARD  *
133*a3434a2dSAnthony PERARD  *      This option doesn't require a backend to use O_DIRECT, so it
134*a3434a2dSAnthony PERARD  *      should not be used to try to control the caching behaviour.
135*a3434a2dSAnthony PERARD  *
136*a3434a2dSAnthony PERARD  *--------------------------------- Features ---------------------------------
137*a3434a2dSAnthony PERARD  *
138*a3434a2dSAnthony PERARD  * feature-barrier
139*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
140*a3434a2dSAnthony PERARD  *      Default Value:  0
141*a3434a2dSAnthony PERARD  *
142*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the backend can process requests
143*a3434a2dSAnthony PERARD  *      containing the BLKIF_OP_WRITE_BARRIER request opcode.  Requests
144*a3434a2dSAnthony PERARD  *      of this type may still be returned at any time with the
145*a3434a2dSAnthony PERARD  *      BLKIF_RSP_EOPNOTSUPP result code.
146*a3434a2dSAnthony PERARD  *
147*a3434a2dSAnthony PERARD  * feature-flush-cache
148*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
149*a3434a2dSAnthony PERARD  *      Default Value:  0
150*a3434a2dSAnthony PERARD  *
151*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the backend can process requests
152*a3434a2dSAnthony PERARD  *      containing the BLKIF_OP_FLUSH_DISKCACHE request opcode.  Requests
153*a3434a2dSAnthony PERARD  *      of this type may still be returned at any time with the
154*a3434a2dSAnthony PERARD  *      BLKIF_RSP_EOPNOTSUPP result code.
155*a3434a2dSAnthony PERARD  *
156*a3434a2dSAnthony PERARD  * feature-discard
157*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
158*a3434a2dSAnthony PERARD  *      Default Value:  0
159*a3434a2dSAnthony PERARD  *
160*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the backend can process requests
161*a3434a2dSAnthony PERARD  *      containing the BLKIF_OP_DISCARD request opcode.  Requests
162*a3434a2dSAnthony PERARD  *      of this type may still be returned at any time with the
163*a3434a2dSAnthony PERARD  *      BLKIF_RSP_EOPNOTSUPP result code.
164*a3434a2dSAnthony PERARD  *
165*a3434a2dSAnthony PERARD  * feature-persistent
166*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
167*a3434a2dSAnthony PERARD  *      Default Value:  0
168*a3434a2dSAnthony PERARD  *      Notes: 7
169*a3434a2dSAnthony PERARD  *
170*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the backend can keep the grants used
171*a3434a2dSAnthony PERARD  *      by the frontend driver mapped, so the same set of grants should be
172*a3434a2dSAnthony PERARD  *      used in all transactions. The maximum number of grants the backend
173*a3434a2dSAnthony PERARD  *      can map persistently depends on the implementation, but ideally it
174*a3434a2dSAnthony PERARD  *      should be RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. Using this
175*a3434a2dSAnthony PERARD  *      feature the backend doesn't need to unmap each grant, preventing
176*a3434a2dSAnthony PERARD  *      costly TLB flushes. The backend driver should only map grants
177*a3434a2dSAnthony PERARD  *      persistently if the frontend supports it. If a backend driver chooses
178*a3434a2dSAnthony PERARD  *      to use the persistent protocol when the frontend doesn't support it,
179*a3434a2dSAnthony PERARD  *      it will probably hit the maximum number of persistently mapped grants
180*a3434a2dSAnthony PERARD  *      (due to the fact that the frontend won't be reusing the same grants),
181*a3434a2dSAnthony PERARD  *      and fall back to non-persistent mode. Backend implementations may
182*a3434a2dSAnthony PERARD  *      shrink or expand the number of persistently mapped grants without
183*a3434a2dSAnthony PERARD  *      notifying the frontend depending on memory constraints (this might
184*a3434a2dSAnthony PERARD  *      cause a performance degradation).
185*a3434a2dSAnthony PERARD  *
186*a3434a2dSAnthony PERARD  *      If a backend driver wants to limit the maximum number of persistently
187*a3434a2dSAnthony PERARD  *      mapped grants to a value less than RING_SIZE *
188*a3434a2dSAnthony PERARD  *      BLKIF_MAX_SEGMENTS_PER_REQUEST a LRU strategy should be used to
189*a3434a2dSAnthony PERARD  *      discard the grants that are less commonly used. Using a LRU in the
190*a3434a2dSAnthony PERARD  *      backend driver paired with a LIFO queue in the frontend will
191*a3434a2dSAnthony PERARD  *      allow us to have better performance in this scenario.
192*a3434a2dSAnthony PERARD  *
193*a3434a2dSAnthony PERARD  *----------------------- Request Transport Parameters ------------------------
194*a3434a2dSAnthony PERARD  *
195*a3434a2dSAnthony PERARD  * max-ring-page-order
196*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
197*a3434a2dSAnthony PERARD  *      Default Value:  0
198*a3434a2dSAnthony PERARD  *      Notes:          1, 3
199*a3434a2dSAnthony PERARD  *
200*a3434a2dSAnthony PERARD  *      The maximum supported size of the request ring buffer in units of
201*a3434a2dSAnthony PERARD  *      lb(machine pages). (e.g. 0 == 1 page,  1 = 2 pages, 2 == 4 pages,
202*a3434a2dSAnthony PERARD  *      etc.).
203*a3434a2dSAnthony PERARD  *
204*a3434a2dSAnthony PERARD  * max-ring-pages
205*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
206*a3434a2dSAnthony PERARD  *      Default Value:  1
207*a3434a2dSAnthony PERARD  *      Notes:          DEPRECATED, 2, 3
208*a3434a2dSAnthony PERARD  *
209*a3434a2dSAnthony PERARD  *      The maximum supported size of the request ring buffer in units of
210*a3434a2dSAnthony PERARD  *      machine pages.  The value must be a power of 2.
211*a3434a2dSAnthony PERARD  *
212*a3434a2dSAnthony PERARD  *------------------------- Backend Device Properties -------------------------
213*a3434a2dSAnthony PERARD  *
214*a3434a2dSAnthony PERARD  * discard-enable
215*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
216*a3434a2dSAnthony PERARD  *      Default Value:  1
217*a3434a2dSAnthony PERARD  *
218*a3434a2dSAnthony PERARD  *      This optional property, set by the toolstack, instructs the backend
219*a3434a2dSAnthony PERARD  *      to offer (or not to offer) discard to the frontend. If the property
220*a3434a2dSAnthony PERARD  *      is missing the backend should offer discard if the backing storage
221*a3434a2dSAnthony PERARD  *      actually supports it.
222*a3434a2dSAnthony PERARD  *
223*a3434a2dSAnthony PERARD  * discard-alignment
224*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
225*a3434a2dSAnthony PERARD  *      Default Value:  0
226*a3434a2dSAnthony PERARD  *      Notes:          4, 5
227*a3434a2dSAnthony PERARD  *
228*a3434a2dSAnthony PERARD  *      The offset, in bytes from the beginning of the virtual block device,
229*a3434a2dSAnthony PERARD  *      to the first, addressable, discard extent on the underlying device.
230*a3434a2dSAnthony PERARD  *
231*a3434a2dSAnthony PERARD  * discard-granularity
232*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
233*a3434a2dSAnthony PERARD  *      Default Value:  <"sector-size">
234*a3434a2dSAnthony PERARD  *      Notes:          4
235*a3434a2dSAnthony PERARD  *
236*a3434a2dSAnthony PERARD  *      The size, in bytes, of the individually addressable discard extents
237*a3434a2dSAnthony PERARD  *      of the underlying device.
238*a3434a2dSAnthony PERARD  *
239*a3434a2dSAnthony PERARD  * discard-secure
240*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
241*a3434a2dSAnthony PERARD  *      Default Value:  0
242*a3434a2dSAnthony PERARD  *      Notes:          10
243*a3434a2dSAnthony PERARD  *
244*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the backend can process BLKIF_OP_DISCARD
245*a3434a2dSAnthony PERARD  *      requests with the BLKIF_DISCARD_SECURE flag set.
246*a3434a2dSAnthony PERARD  *
247*a3434a2dSAnthony PERARD  * info
248*a3434a2dSAnthony PERARD  *      Values:         <uint32_t> (bitmap)
249*a3434a2dSAnthony PERARD  *
250*a3434a2dSAnthony PERARD  *      A collection of bit flags describing attributes of the backing
251*a3434a2dSAnthony PERARD  *      device.  The VDISK_* macros define the meaning of each bit
252*a3434a2dSAnthony PERARD  *      location.
253*a3434a2dSAnthony PERARD  *
254*a3434a2dSAnthony PERARD  * sector-size
255*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
256*a3434a2dSAnthony PERARD  *
257*a3434a2dSAnthony PERARD  *      The logical block size, in bytes, of the underlying storage. This
258*a3434a2dSAnthony PERARD  *      must be a power of two with a minimum value of 512.
259*a3434a2dSAnthony PERARD  *
260*a3434a2dSAnthony PERARD  *      NOTE: Because of implementation bugs in some frontends this must be
261*a3434a2dSAnthony PERARD  *            set to 512, unless the frontend advertizes a non-zero value
262*a3434a2dSAnthony PERARD  *            in its "feature-large-sector-size" xenbus node. (See below).
263*a3434a2dSAnthony PERARD  *
264*a3434a2dSAnthony PERARD  * physical-sector-size
265*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
266*a3434a2dSAnthony PERARD  *      Default Value:  <"sector-size">
267*a3434a2dSAnthony PERARD  *
268*a3434a2dSAnthony PERARD  *      The physical block size, in bytes, of the backend storage. This
269*a3434a2dSAnthony PERARD  *      must be an integer multiple of "sector-size".
270*a3434a2dSAnthony PERARD  *
271*a3434a2dSAnthony PERARD  * sectors
272*a3434a2dSAnthony PERARD  *      Values:         <uint64_t>
273*a3434a2dSAnthony PERARD  *
274*a3434a2dSAnthony PERARD  *      The size of the backend device, expressed in units of "sector-size".
275*a3434a2dSAnthony PERARD  *      The product of "sector-size" and "sectors" must also be an integer
276*a3434a2dSAnthony PERARD  *      multiple of "physical-sector-size", if that node is present.
277*a3434a2dSAnthony PERARD  *
278*a3434a2dSAnthony PERARD  *****************************************************************************
279*a3434a2dSAnthony PERARD  *                            Frontend XenBus Nodes
280*a3434a2dSAnthony PERARD  *****************************************************************************
281*a3434a2dSAnthony PERARD  *
282*a3434a2dSAnthony PERARD  *----------------------- Request Transport Parameters -----------------------
283*a3434a2dSAnthony PERARD  *
284*a3434a2dSAnthony PERARD  * event-channel
285*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
286*a3434a2dSAnthony PERARD  *
287*a3434a2dSAnthony PERARD  *      The identifier of the Xen event channel used to signal activity
288*a3434a2dSAnthony PERARD  *      in the ring buffer.
289*a3434a2dSAnthony PERARD  *
290*a3434a2dSAnthony PERARD  * ring-ref
291*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
292*a3434a2dSAnthony PERARD  *      Notes:          6
293*a3434a2dSAnthony PERARD  *
294*a3434a2dSAnthony PERARD  *      The Xen grant reference granting permission for the backend to map
295*a3434a2dSAnthony PERARD  *      the sole page in a single page sized ring buffer.
296*a3434a2dSAnthony PERARD  *
297*a3434a2dSAnthony PERARD  * ring-ref%u
298*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
299*a3434a2dSAnthony PERARD  *      Notes:          6
300*a3434a2dSAnthony PERARD  *
301*a3434a2dSAnthony PERARD  *      For a frontend providing a multi-page ring, a "number of ring pages"
302*a3434a2dSAnthony PERARD  *      sized list of nodes, each containing a Xen grant reference granting
303*a3434a2dSAnthony PERARD  *      permission for the backend to map the page of the ring located
304*a3434a2dSAnthony PERARD  *      at page index "%u".  Page indexes are zero based.
305*a3434a2dSAnthony PERARD  *
306*a3434a2dSAnthony PERARD  * protocol
307*a3434a2dSAnthony PERARD  *      Values:         string (XEN_IO_PROTO_ABI_*)
308*a3434a2dSAnthony PERARD  *      Default Value:  XEN_IO_PROTO_ABI_NATIVE
309*a3434a2dSAnthony PERARD  *
310*a3434a2dSAnthony PERARD  *      The machine ABI rules governing the format of all ring request and
311*a3434a2dSAnthony PERARD  *      response structures.
312*a3434a2dSAnthony PERARD  *
313*a3434a2dSAnthony PERARD  * ring-page-order
314*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
315*a3434a2dSAnthony PERARD  *      Default Value:  0
316*a3434a2dSAnthony PERARD  *      Maximum Value:  MAX(ffs(max-ring-pages) - 1, max-ring-page-order)
317*a3434a2dSAnthony PERARD  *      Notes:          1, 3
318*a3434a2dSAnthony PERARD  *
319*a3434a2dSAnthony PERARD  *      The size of the frontend allocated request ring buffer in units
320*a3434a2dSAnthony PERARD  *      of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
321*a3434a2dSAnthony PERARD  *      etc.).
322*a3434a2dSAnthony PERARD  *
323*a3434a2dSAnthony PERARD  * num-ring-pages
324*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
325*a3434a2dSAnthony PERARD  *      Default Value:  1
326*a3434a2dSAnthony PERARD  *      Maximum Value:  MAX(max-ring-pages,(0x1 << max-ring-page-order))
327*a3434a2dSAnthony PERARD  *      Notes:          DEPRECATED, 2, 3
328*a3434a2dSAnthony PERARD  *
329*a3434a2dSAnthony PERARD  *      The size of the frontend allocated request ring buffer in units of
330*a3434a2dSAnthony PERARD  *      machine pages.  The value must be a power of 2.
331*a3434a2dSAnthony PERARD  *
332*a3434a2dSAnthony PERARD  *--------------------------------- Features ---------------------------------
333*a3434a2dSAnthony PERARD  *
334*a3434a2dSAnthony PERARD  * feature-persistent
335*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
336*a3434a2dSAnthony PERARD  *      Default Value:  0
337*a3434a2dSAnthony PERARD  *      Notes: 7, 8, 9
338*a3434a2dSAnthony PERARD  *
339*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the frontend will reuse the same grants
340*a3434a2dSAnthony PERARD  *      for all transactions, allowing the backend to map them with write
341*a3434a2dSAnthony PERARD  *      access (even when it should be read-only). If the frontend hits the
342*a3434a2dSAnthony PERARD  *      maximum number of allowed persistently mapped grants, it can fallback
343*a3434a2dSAnthony PERARD  *      to non persistent mode. This will cause a performance degradation,
344*a3434a2dSAnthony PERARD  *      since the the backend driver will still try to map those grants
345*a3434a2dSAnthony PERARD  *      persistently. Since the persistent grants protocol is compatible with
346*a3434a2dSAnthony PERARD  *      the previous protocol, a frontend driver can choose to work in
347*a3434a2dSAnthony PERARD  *      persistent mode even when the backend doesn't support it.
348*a3434a2dSAnthony PERARD  *
349*a3434a2dSAnthony PERARD  *      It is recommended that the frontend driver stores the persistently
350*a3434a2dSAnthony PERARD  *      mapped grants in a LIFO queue, so a subset of all persistently mapped
351*a3434a2dSAnthony PERARD  *      grants gets used commonly. This is done in case the backend driver
352*a3434a2dSAnthony PERARD  *      decides to limit the maximum number of persistently mapped grants
353*a3434a2dSAnthony PERARD  *      to a value less than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
354*a3434a2dSAnthony PERARD  *
355*a3434a2dSAnthony PERARD  * feature-large-sector-size
356*a3434a2dSAnthony PERARD  *      Values:         0/1 (boolean)
357*a3434a2dSAnthony PERARD  *      Default Value:  0
358*a3434a2dSAnthony PERARD  *
359*a3434a2dSAnthony PERARD  *      A value of "1" indicates that the frontend will correctly supply and
360*a3434a2dSAnthony PERARD  *      interpret all sector-based quantities in terms of the "sector-size"
361*a3434a2dSAnthony PERARD  *      value supplied in the backend info, whatever that may be set to.
362*a3434a2dSAnthony PERARD  *      If this node is not present or its value is "0" then it is assumed
363*a3434a2dSAnthony PERARD  *      that the frontend requires that the logical block size is 512 as it
364*a3434a2dSAnthony PERARD  *      is hardcoded (which is the case in some frontend implementations).
365*a3434a2dSAnthony PERARD  *
366*a3434a2dSAnthony PERARD  *------------------------- Virtual Device Properties -------------------------
367*a3434a2dSAnthony PERARD  *
368*a3434a2dSAnthony PERARD  * device-type
369*a3434a2dSAnthony PERARD  *      Values:         "disk", "cdrom", "floppy", etc.
370*a3434a2dSAnthony PERARD  *
371*a3434a2dSAnthony PERARD  * virtual-device
372*a3434a2dSAnthony PERARD  *      Values:         <uint32_t>
373*a3434a2dSAnthony PERARD  *
374*a3434a2dSAnthony PERARD  *      A value indicating the physical device to virtualize within the
375*a3434a2dSAnthony PERARD  *      frontend's domain.  (e.g. "The first ATA disk", "The third SCSI
376*a3434a2dSAnthony PERARD  *      disk", etc.)
377*a3434a2dSAnthony PERARD  *
378*a3434a2dSAnthony PERARD  *      See docs/misc/vbd-interface.txt for details on the format of this
379*a3434a2dSAnthony PERARD  *      value.
380*a3434a2dSAnthony PERARD  *
381*a3434a2dSAnthony PERARD  * Notes
382*a3434a2dSAnthony PERARD  * -----
383*a3434a2dSAnthony PERARD  * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer
384*a3434a2dSAnthony PERARD  *     PV drivers.
385*a3434a2dSAnthony PERARD  * (2) Multi-page ring buffer scheme first used in some RedHat distributions
386*a3434a2dSAnthony PERARD  *     including a distribution deployed on certain nodes of the Amazon
387*a3434a2dSAnthony PERARD  *     EC2 cluster.
388*a3434a2dSAnthony PERARD  * (3) Support for multi-page ring buffers was implemented independently,
389*a3434a2dSAnthony PERARD  *     in slightly different forms, by both Citrix and RedHat/Amazon.
390*a3434a2dSAnthony PERARD  *     For full interoperability, block front and backends should publish
391*a3434a2dSAnthony PERARD  *     identical ring parameters, adjusted for unit differences, to the
392*a3434a2dSAnthony PERARD  *     XenStore nodes used in both schemes.
393*a3434a2dSAnthony PERARD  * (4) Devices that support discard functionality may internally allocate space
394*a3434a2dSAnthony PERARD  *     (discardable extents) in units that are larger than the exported logical
395*a3434a2dSAnthony PERARD  *     block size. If the backing device has such discardable extents the
396*a3434a2dSAnthony PERARD  *     backend should provide both discard-granularity and discard-alignment.
397*a3434a2dSAnthony PERARD  *     Providing just one of the two may be considered an error by the frontend.
398*a3434a2dSAnthony PERARD  *     Backends supporting discard should include discard-granularity and
399*a3434a2dSAnthony PERARD  *     discard-alignment even if it supports discarding individual sectors.
400*a3434a2dSAnthony PERARD  *     Frontends should assume discard-alignment == 0 and discard-granularity
401*a3434a2dSAnthony PERARD  *     == sector size if these keys are missing.
402*a3434a2dSAnthony PERARD  * (5) The discard-alignment parameter allows a physical device to be
403*a3434a2dSAnthony PERARD  *     partitioned into virtual devices that do not necessarily begin or
404*a3434a2dSAnthony PERARD  *     end on a discardable extent boundary.
405*a3434a2dSAnthony PERARD  * (6) When there is only a single page allocated to the request ring,
406*a3434a2dSAnthony PERARD  *     'ring-ref' is used to communicate the grant reference for this
407*a3434a2dSAnthony PERARD  *     page to the backend.  When using a multi-page ring, the 'ring-ref'
408*a3434a2dSAnthony PERARD  *     node is not created.  Instead 'ring-ref0' - 'ring-refN' are used.
409*a3434a2dSAnthony PERARD  * (7) When using persistent grants data has to be copied from/to the page
410*a3434a2dSAnthony PERARD  *     where the grant is currently mapped. The overhead of doing this copy
411*a3434a2dSAnthony PERARD  *     however doesn't suppress the speed improvement of not having to unmap
412*a3434a2dSAnthony PERARD  *     the grants.
413*a3434a2dSAnthony PERARD  * (8) The frontend driver has to allow the backend driver to map all grants
414*a3434a2dSAnthony PERARD  *     with write access, even when they should be mapped read-only, since
415*a3434a2dSAnthony PERARD  *     further requests may reuse these grants and require write permissions.
416*a3434a2dSAnthony PERARD  * (9) Linux implementation doesn't have a limit on the maximum number of
417*a3434a2dSAnthony PERARD  *     grants that can be persistently mapped in the frontend driver, but
418*a3434a2dSAnthony PERARD  *     due to the frontent driver implementation it should never be bigger
419*a3434a2dSAnthony PERARD  *     than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
420*a3434a2dSAnthony PERARD  *(10) The discard-secure property may be present and will be set to 1 if the
421*a3434a2dSAnthony PERARD  *     backing device supports secure discard.
422*a3434a2dSAnthony PERARD  *(11) Only used by Linux and NetBSD.
423*a3434a2dSAnthony PERARD  */
424*a3434a2dSAnthony PERARD 
425*a3434a2dSAnthony PERARD /*
426*a3434a2dSAnthony PERARD  * Multiple hardware queues/rings:
427*a3434a2dSAnthony PERARD  * If supported, the backend will write the key "multi-queue-max-queues" to
428*a3434a2dSAnthony PERARD  * the directory for that vbd, and set its value to the maximum supported
429*a3434a2dSAnthony PERARD  * number of queues.
430*a3434a2dSAnthony PERARD  * Frontends that are aware of this feature and wish to use it can write the
431*a3434a2dSAnthony PERARD  * key "multi-queue-num-queues" with the number they wish to use, which must be
432*a3434a2dSAnthony PERARD  * greater than zero, and no more than the value reported by the backend in
433*a3434a2dSAnthony PERARD  * "multi-queue-max-queues".
434*a3434a2dSAnthony PERARD  *
435*a3434a2dSAnthony PERARD  * For frontends requesting just one queue, the usual event-channel and
436*a3434a2dSAnthony PERARD  * ring-ref keys are written as before, simplifying the backend processing
437*a3434a2dSAnthony PERARD  * to avoid distinguishing between a frontend that doesn't understand the
438*a3434a2dSAnthony PERARD  * multi-queue feature, and one that does, but requested only one queue.
439*a3434a2dSAnthony PERARD  *
440*a3434a2dSAnthony PERARD  * Frontends requesting two or more queues must not write the toplevel
441*a3434a2dSAnthony PERARD  * event-channel and ring-ref keys, instead writing those keys under sub-keys
442*a3434a2dSAnthony PERARD  * having the name "queue-N" where N is the integer ID of the queue/ring for
443*a3434a2dSAnthony PERARD  * which those keys belong. Queues are indexed from zero.
444*a3434a2dSAnthony PERARD  * For example, a frontend with two queues must write the following set of
445*a3434a2dSAnthony PERARD  * queue-related keys:
446*a3434a2dSAnthony PERARD  *
447*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/multi-queue-num-queues = "2"
448*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0 = ""
449*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0/ring-ref = "<ring-ref#0>"
450*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0/event-channel = "<evtchn#0>"
451*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1 = ""
452*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1/ring-ref = "<ring-ref#1>"
453*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1/event-channel = "<evtchn#1>"
454*a3434a2dSAnthony PERARD  *
455*a3434a2dSAnthony PERARD  * It is also possible to use multiple queues/rings together with
456*a3434a2dSAnthony PERARD  * feature multi-page ring buffer.
457*a3434a2dSAnthony PERARD  * For example, a frontend requests two queues/rings and the size of each ring
458*a3434a2dSAnthony PERARD  * buffer is two pages must write the following set of related keys:
459*a3434a2dSAnthony PERARD  *
460*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/multi-queue-num-queues = "2"
461*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/ring-page-order = "1"
462*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0 = ""
463*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0/ring-ref0 = "<ring-ref#0>"
464*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0/ring-ref1 = "<ring-ref#1>"
465*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-0/event-channel = "<evtchn#0>"
466*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1 = ""
467*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1/ring-ref0 = "<ring-ref#2>"
468*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1/ring-ref1 = "<ring-ref#3>"
469*a3434a2dSAnthony PERARD  * /local/domain/1/device/vbd/0/queue-1/event-channel = "<evtchn#1>"
470*a3434a2dSAnthony PERARD  *
471*a3434a2dSAnthony PERARD  */
472*a3434a2dSAnthony PERARD 
473*a3434a2dSAnthony PERARD /*
474*a3434a2dSAnthony PERARD  * STATE DIAGRAMS
475*a3434a2dSAnthony PERARD  *
476*a3434a2dSAnthony PERARD  *****************************************************************************
477*a3434a2dSAnthony PERARD  *                                   Startup                                 *
478*a3434a2dSAnthony PERARD  *****************************************************************************
479*a3434a2dSAnthony PERARD  *
480*a3434a2dSAnthony PERARD  * Tool stack creates front and back nodes with state XenbusStateInitialising.
481*a3434a2dSAnthony PERARD  *
482*a3434a2dSAnthony PERARD  * Front                                Back
483*a3434a2dSAnthony PERARD  * =================================    =====================================
484*a3434a2dSAnthony PERARD  * XenbusStateInitialising              XenbusStateInitialising
485*a3434a2dSAnthony PERARD  *  o Query virtual device               o Query backend device identification
486*a3434a2dSAnthony PERARD  *    properties.                          data.
487*a3434a2dSAnthony PERARD  *  o Setup OS device instance.          o Open and validate backend device.
488*a3434a2dSAnthony PERARD  *                                       o Publish backend features and
489*a3434a2dSAnthony PERARD  *                                         transport parameters.
490*a3434a2dSAnthony PERARD  *                                                      |
491*a3434a2dSAnthony PERARD  *                                                      |
492*a3434a2dSAnthony PERARD  *                                                      V
493*a3434a2dSAnthony PERARD  *                                      XenbusStateInitWait
494*a3434a2dSAnthony PERARD  *
495*a3434a2dSAnthony PERARD  * o Query backend features and
496*a3434a2dSAnthony PERARD  *   transport parameters.
497*a3434a2dSAnthony PERARD  * o Allocate and initialize the
498*a3434a2dSAnthony PERARD  *   request ring.
499*a3434a2dSAnthony PERARD  * o Publish transport parameters
500*a3434a2dSAnthony PERARD  *   that will be in effect during
501*a3434a2dSAnthony PERARD  *   this connection.
502*a3434a2dSAnthony PERARD  *              |
503*a3434a2dSAnthony PERARD  *              |
504*a3434a2dSAnthony PERARD  *              V
505*a3434a2dSAnthony PERARD  * XenbusStateInitialised
506*a3434a2dSAnthony PERARD  *
507*a3434a2dSAnthony PERARD  *                                       o Query frontend transport parameters.
508*a3434a2dSAnthony PERARD  *                                       o Connect to the request ring and
509*a3434a2dSAnthony PERARD  *                                         event channel.
510*a3434a2dSAnthony PERARD  *                                       o Publish backend device properties.
511*a3434a2dSAnthony PERARD  *                                                      |
512*a3434a2dSAnthony PERARD  *                                                      |
513*a3434a2dSAnthony PERARD  *                                                      V
514*a3434a2dSAnthony PERARD  *                                      XenbusStateConnected
515*a3434a2dSAnthony PERARD  *
516*a3434a2dSAnthony PERARD  *  o Query backend device properties.
517*a3434a2dSAnthony PERARD  *  o Finalize OS virtual device
518*a3434a2dSAnthony PERARD  *    instance.
519*a3434a2dSAnthony PERARD  *              |
520*a3434a2dSAnthony PERARD  *              |
521*a3434a2dSAnthony PERARD  *              V
522*a3434a2dSAnthony PERARD  * XenbusStateConnected
523*a3434a2dSAnthony PERARD  *
524*a3434a2dSAnthony PERARD  * Note: Drivers that do not support any optional features, or the negotiation
525*a3434a2dSAnthony PERARD  *       of transport parameters, can skip certain states in the state machine:
526*a3434a2dSAnthony PERARD  *
527*a3434a2dSAnthony PERARD  *       o A frontend may transition to XenbusStateInitialised without
528*a3434a2dSAnthony PERARD  *         waiting for the backend to enter XenbusStateInitWait.  In this
529*a3434a2dSAnthony PERARD  *         case, default transport parameters are in effect and any
530*a3434a2dSAnthony PERARD  *         transport parameters published by the frontend must contain
531*a3434a2dSAnthony PERARD  *         their default values.
532*a3434a2dSAnthony PERARD  *
533*a3434a2dSAnthony PERARD  *       o A backend may transition to XenbusStateInitialised, bypassing
534*a3434a2dSAnthony PERARD  *         XenbusStateInitWait, without waiting for the frontend to first
535*a3434a2dSAnthony PERARD  *         enter the XenbusStateInitialised state.  In this case, default
536*a3434a2dSAnthony PERARD  *         transport parameters are in effect and any transport parameters
537*a3434a2dSAnthony PERARD  *         published by the backend must contain their default values.
538*a3434a2dSAnthony PERARD  *
539*a3434a2dSAnthony PERARD  *       Drivers that support optional features and/or transport parameter
540*a3434a2dSAnthony PERARD  *       negotiation must tolerate these additional state transition paths.
541*a3434a2dSAnthony PERARD  *       In general this means performing the work of any skipped state
542*a3434a2dSAnthony PERARD  *       transition, if it has not already been performed, in addition to the
543*a3434a2dSAnthony PERARD  *       work associated with entry into the current state.
544*a3434a2dSAnthony PERARD  */
545*a3434a2dSAnthony PERARD 
546*a3434a2dSAnthony PERARD /*
547*a3434a2dSAnthony PERARD  * REQUEST CODES.
548*a3434a2dSAnthony PERARD  */
549*a3434a2dSAnthony PERARD #define BLKIF_OP_READ              0
550*a3434a2dSAnthony PERARD #define BLKIF_OP_WRITE             1
551*a3434a2dSAnthony PERARD /*
552*a3434a2dSAnthony PERARD  * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER
553*a3434a2dSAnthony PERARD  * operation code ("barrier request") must be completed prior to the
554*a3434a2dSAnthony PERARD  * execution of the barrier request.  All writes issued after the barrier
555*a3434a2dSAnthony PERARD  * request must not execute until after the completion of the barrier request.
556*a3434a2dSAnthony PERARD  *
557*a3434a2dSAnthony PERARD  * Optional.  See "feature-barrier" XenBus node documentation above.
558*a3434a2dSAnthony PERARD  */
559*a3434a2dSAnthony PERARD #define BLKIF_OP_WRITE_BARRIER     2
560*a3434a2dSAnthony PERARD /*
561*a3434a2dSAnthony PERARD  * Commit any uncommitted contents of the backing device's volatile cache
562*a3434a2dSAnthony PERARD  * to stable storage.
563*a3434a2dSAnthony PERARD  *
564*a3434a2dSAnthony PERARD  * Optional.  See "feature-flush-cache" XenBus node documentation above.
565*a3434a2dSAnthony PERARD  */
566*a3434a2dSAnthony PERARD #define BLKIF_OP_FLUSH_DISKCACHE   3
567*a3434a2dSAnthony PERARD /*
568*a3434a2dSAnthony PERARD  * Used in SLES sources for device specific command packet
569*a3434a2dSAnthony PERARD  * contained within the request. Reserved for that purpose.
570*a3434a2dSAnthony PERARD  */
571*a3434a2dSAnthony PERARD #define BLKIF_OP_RESERVED_1        4
572*a3434a2dSAnthony PERARD /*
573*a3434a2dSAnthony PERARD  * Indicate to the backend device that a region of storage is no longer in
574*a3434a2dSAnthony PERARD  * use, and may be discarded at any time without impact to the client.  If
575*a3434a2dSAnthony PERARD  * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the
576*a3434a2dSAnthony PERARD  * discarded region on the device must be rendered unrecoverable before the
577*a3434a2dSAnthony PERARD  * command returns.
578*a3434a2dSAnthony PERARD  *
579*a3434a2dSAnthony PERARD  * This operation is analogous to performing a trim (ATA) or unamp (SCSI),
580*a3434a2dSAnthony PERARD  * command on a native device.
581*a3434a2dSAnthony PERARD  *
582*a3434a2dSAnthony PERARD  * More information about trim/unmap operations can be found at:
583*a3434a2dSAnthony PERARD  * http://t13.org/Documents/UploadedDocuments/docs2008/
584*a3434a2dSAnthony PERARD  *     e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
585*a3434a2dSAnthony PERARD  * http://www.seagate.com/staticfiles/support/disc/manuals/
586*a3434a2dSAnthony PERARD  *     Interface%20manuals/100293068c.pdf
587*a3434a2dSAnthony PERARD  *
588*a3434a2dSAnthony PERARD  * Optional.  See "feature-discard", "discard-alignment",
589*a3434a2dSAnthony PERARD  * "discard-granularity", and "discard-secure" in the XenBus node
590*a3434a2dSAnthony PERARD  * documentation above.
591*a3434a2dSAnthony PERARD  */
592*a3434a2dSAnthony PERARD #define BLKIF_OP_DISCARD           5
593*a3434a2dSAnthony PERARD 
594*a3434a2dSAnthony PERARD /*
595*a3434a2dSAnthony PERARD  * Recognized if "feature-max-indirect-segments" in present in the backend
596*a3434a2dSAnthony PERARD  * xenbus info. The "feature-max-indirect-segments" node contains the maximum
597*a3434a2dSAnthony PERARD  * number of segments allowed by the backend per request. If the node is
598*a3434a2dSAnthony PERARD  * present, the frontend might use blkif_request_indirect structs in order to
599*a3434a2dSAnthony PERARD  * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The
600*a3434a2dSAnthony PERARD  * maximum number of indirect segments is fixed by the backend, but the
601*a3434a2dSAnthony PERARD  * frontend can issue requests with any number of indirect segments as long as
602*a3434a2dSAnthony PERARD  * it's less than the number provided by the backend. The indirect_grefs field
603*a3434a2dSAnthony PERARD  * in blkif_request_indirect should be filled by the frontend with the
604*a3434a2dSAnthony PERARD  * grant references of the pages that are holding the indirect segments.
605*a3434a2dSAnthony PERARD  * These pages are filled with an array of blkif_request_segment that hold the
606*a3434a2dSAnthony PERARD  * information about the segments. The number of indirect pages to use is
607*a3434a2dSAnthony PERARD  * determined by the number of segments an indirect request contains. Every
608*a3434a2dSAnthony PERARD  * indirect page can contain a maximum of
609*a3434a2dSAnthony PERARD  * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
610*a3434a2dSAnthony PERARD  * calculate the number of indirect pages to use we have to do
611*a3434a2dSAnthony PERARD  * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
612*a3434a2dSAnthony PERARD  *
613*a3434a2dSAnthony PERARD  * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
614*a3434a2dSAnthony PERARD  * create the "feature-max-indirect-segments" node!
615*a3434a2dSAnthony PERARD  */
616*a3434a2dSAnthony PERARD #define BLKIF_OP_INDIRECT          6
617*a3434a2dSAnthony PERARD 
618*a3434a2dSAnthony PERARD /*
619*a3434a2dSAnthony PERARD  * Maximum scatter/gather segments per request.
620*a3434a2dSAnthony PERARD  * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
621*a3434a2dSAnthony PERARD  * NB. This could be 12 if the ring indexes weren't stored in the same page.
622*a3434a2dSAnthony PERARD  */
623*a3434a2dSAnthony PERARD #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
624*a3434a2dSAnthony PERARD 
625*a3434a2dSAnthony PERARD /*
626*a3434a2dSAnthony PERARD  * Maximum number of indirect pages to use per request.
627*a3434a2dSAnthony PERARD  */
628*a3434a2dSAnthony PERARD #define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
629*a3434a2dSAnthony PERARD 
630*a3434a2dSAnthony PERARD /*
631*a3434a2dSAnthony PERARD  * NB. 'first_sect' and 'last_sect' in blkif_request_segment, as well as
632*a3434a2dSAnthony PERARD  * 'sector_number' in blkif_request, blkif_request_discard and
633*a3434a2dSAnthony PERARD  * blkif_request_indirect are sector-based quantities. See the description
634*a3434a2dSAnthony PERARD  * of the "feature-large-sector-size" frontend xenbus node above for
635*a3434a2dSAnthony PERARD  * more information.
636*a3434a2dSAnthony PERARD  */
637*a3434a2dSAnthony PERARD struct blkif_request_segment {
638*a3434a2dSAnthony PERARD     grant_ref_t gref;        /* reference to I/O buffer frame        */
639*a3434a2dSAnthony PERARD     /* @first_sect: first sector in frame to transfer (inclusive).   */
640*a3434a2dSAnthony PERARD     /* @last_sect: last sector in frame to transfer (inclusive).     */
641*a3434a2dSAnthony PERARD     uint8_t     first_sect, last_sect;
642*a3434a2dSAnthony PERARD };
643*a3434a2dSAnthony PERARD 
644*a3434a2dSAnthony PERARD /*
645*a3434a2dSAnthony PERARD  * Starting ring element for any I/O request.
646*a3434a2dSAnthony PERARD  */
647*a3434a2dSAnthony PERARD struct blkif_request {
648*a3434a2dSAnthony PERARD     uint8_t        operation;    /* BLKIF_OP_???                         */
649*a3434a2dSAnthony PERARD     uint8_t        nr_segments;  /* number of segments                   */
650*a3434a2dSAnthony PERARD     blkif_vdev_t   handle;       /* only for read/write requests         */
651*a3434a2dSAnthony PERARD     uint64_t       id;           /* private guest value, echoed in resp  */
652*a3434a2dSAnthony PERARD     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
653*a3434a2dSAnthony PERARD     struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
654*a3434a2dSAnthony PERARD };
655*a3434a2dSAnthony PERARD typedef struct blkif_request blkif_request_t;
656*a3434a2dSAnthony PERARD 
657*a3434a2dSAnthony PERARD /*
658*a3434a2dSAnthony PERARD  * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD
659*a3434a2dSAnthony PERARD  * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request)
660*a3434a2dSAnthony PERARD  */
661*a3434a2dSAnthony PERARD struct blkif_request_discard {
662*a3434a2dSAnthony PERARD     uint8_t        operation;    /* BLKIF_OP_DISCARD                     */
663*a3434a2dSAnthony PERARD     uint8_t        flag;         /* BLKIF_DISCARD_SECURE or zero         */
664*a3434a2dSAnthony PERARD #define BLKIF_DISCARD_SECURE (1<<0)  /* ignored if discard-secure=0      */
665*a3434a2dSAnthony PERARD     blkif_vdev_t   handle;       /* same as for read/write requests      */
666*a3434a2dSAnthony PERARD     uint64_t       id;           /* private guest value, echoed in resp  */
667*a3434a2dSAnthony PERARD     blkif_sector_t sector_number;/* start sector idx on disk             */
668*a3434a2dSAnthony PERARD     uint64_t       nr_sectors;   /* number of contiguous sectors to discard*/
669*a3434a2dSAnthony PERARD };
670*a3434a2dSAnthony PERARD typedef struct blkif_request_discard blkif_request_discard_t;
671*a3434a2dSAnthony PERARD 
672*a3434a2dSAnthony PERARD struct blkif_request_indirect {
673*a3434a2dSAnthony PERARD     uint8_t        operation;    /* BLKIF_OP_INDIRECT                    */
674*a3434a2dSAnthony PERARD     uint8_t        indirect_op;  /* BLKIF_OP_{READ/WRITE}                */
675*a3434a2dSAnthony PERARD     uint16_t       nr_segments;  /* number of segments                   */
676*a3434a2dSAnthony PERARD     uint64_t       id;           /* private guest value, echoed in resp  */
677*a3434a2dSAnthony PERARD     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
678*a3434a2dSAnthony PERARD     blkif_vdev_t   handle;       /* same as for read/write requests      */
679*a3434a2dSAnthony PERARD     grant_ref_t    indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
680*a3434a2dSAnthony PERARD #ifdef __i386__
681*a3434a2dSAnthony PERARD     uint64_t       pad;          /* Make it 64 byte aligned on i386      */
682*a3434a2dSAnthony PERARD #endif
683*a3434a2dSAnthony PERARD };
684*a3434a2dSAnthony PERARD typedef struct blkif_request_indirect blkif_request_indirect_t;
685*a3434a2dSAnthony PERARD 
686*a3434a2dSAnthony PERARD struct blkif_response {
687*a3434a2dSAnthony PERARD     uint64_t        id;              /* copied from request */
688*a3434a2dSAnthony PERARD     uint8_t         operation;       /* copied from request */
689*a3434a2dSAnthony PERARD     int16_t         status;          /* BLKIF_RSP_???       */
690*a3434a2dSAnthony PERARD };
691*a3434a2dSAnthony PERARD typedef struct blkif_response blkif_response_t;
692*a3434a2dSAnthony PERARD 
693*a3434a2dSAnthony PERARD /*
694*a3434a2dSAnthony PERARD  * STATUS RETURN CODES.
695*a3434a2dSAnthony PERARD  */
696*a3434a2dSAnthony PERARD  /* Operation not supported (only happens on barrier writes). */
697*a3434a2dSAnthony PERARD #define BLKIF_RSP_EOPNOTSUPP  -2
698*a3434a2dSAnthony PERARD  /* Operation failed for some unspecified reason (-EIO). */
699*a3434a2dSAnthony PERARD #define BLKIF_RSP_ERROR       -1
700*a3434a2dSAnthony PERARD  /* Operation completed successfully. */
701*a3434a2dSAnthony PERARD #define BLKIF_RSP_OKAY         0
702*a3434a2dSAnthony PERARD 
703*a3434a2dSAnthony PERARD /*
704*a3434a2dSAnthony PERARD  * Generate blkif ring structures and types.
705*a3434a2dSAnthony PERARD  */
706*a3434a2dSAnthony PERARD DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
707*a3434a2dSAnthony PERARD 
708*a3434a2dSAnthony PERARD #define VDISK_CDROM        0x1
709*a3434a2dSAnthony PERARD #define VDISK_REMOVABLE    0x2
710*a3434a2dSAnthony PERARD #define VDISK_READONLY     0x4
711*a3434a2dSAnthony PERARD 
712*a3434a2dSAnthony PERARD #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
713