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