blkif.h revision 231836
1181624Skmacy/******************************************************************************
2181624Skmacy * blkif.h
3231743Sgibbs *
4181624Skmacy * Unified block-device I/O interface for Xen guest OSes.
5231743Sgibbs *
6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy
7181624Skmacy * of this software and associated documentation files (the "Software"), to
8181624Skmacy * deal in the Software without restriction, including without limitation the
9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is
11181624Skmacy * furnished to do so, subject to the following conditions:
12181624Skmacy *
13181624Skmacy * The above copyright notice and this permission notice shall be included in
14181624Skmacy * all copies or substantial portions of the Software.
15181624Skmacy *
16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22181624Skmacy * DEALINGS IN THE SOFTWARE.
23181624Skmacy *
24181624Skmacy * Copyright (c) 2003-2004, Keir Fraser
25231743Sgibbs * Copyright (c) 2012, Spectra Logic Corporation
26181624Skmacy */
27181624Skmacy
28181624Skmacy#ifndef __XEN_PUBLIC_IO_BLKIF_H__
29181624Skmacy#define __XEN_PUBLIC_IO_BLKIF_H__
30181624Skmacy
31181624Skmacy#include <xen/interface/io/ring.h>
32181624Skmacy#include <xen/interface/grant_table.h>
33181624Skmacy
34181624Skmacy/*
35181624Skmacy * Front->back notifications: When enqueuing a new request, sending a
36181624Skmacy * notification can be made conditional on req_event (i.e., the generic
37181624Skmacy * hold-off mechanism provided by the ring macros). Backends must set
38181624Skmacy * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
39231743Sgibbs *
40181624Skmacy * Back->front notifications: When enqueuing a new response, sending a
41181624Skmacy * notification can be made conditional on rsp_event (i.e., the generic
42181624Skmacy * hold-off mechanism provided by the ring macros). Frontends must set
43181624Skmacy * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
44181624Skmacy */
45181624Skmacy
46181624Skmacy#ifndef blkif_vdev_t
47181624Skmacy#define blkif_vdev_t   uint16_t
48181624Skmacy#endif
49181624Skmacy#define blkif_sector_t uint64_t
50181624Skmacy
51181624Skmacy/*
52231743Sgibbs * Feature and Parameter Negotiation
53231743Sgibbs * =================================
54231743Sgibbs * The two halves of a Xen block driver utilize nodes within the XenStore to
55231743Sgibbs * communicate capabilities and to negotiate operating parameters.  This
56231743Sgibbs * section enumerates these nodes which reside in the respective front and
57231743Sgibbs * backend portions of the XenStore, following the XenBus convention.
58231743Sgibbs *
59231743Sgibbs * All data in the XenStore is stored as strings.  Nodes specifying numeric
60231743Sgibbs * values are encoded in decimal.  Integer value ranges listed below are
61231743Sgibbs * expressed as fixed sized integer types capable of storing the conversion
62231743Sgibbs * of a properly formated node string, without loss of information.
63231743Sgibbs *
64231743Sgibbs * Any specified default value is in effect if the corresponding XenBus node
65231743Sgibbs * is not present in the XenStore.
66231743Sgibbs *
67231743Sgibbs * XenStore nodes in sections marked "PRIVATE" are solely for use by the
68231743Sgibbs * driver side whose XenBus tree contains them.
69231743Sgibbs *
70231743Sgibbs * See the XenBus state transition diagram below for details on when XenBus
71231743Sgibbs * nodes must be published and when they can be queried.
72231743Sgibbs *
73231743Sgibbs *****************************************************************************
74231743Sgibbs *                            Backend XenBus Nodes
75231743Sgibbs *****************************************************************************
76231743Sgibbs *
77231743Sgibbs *------------------ Backend Device Identification (PRIVATE) ------------------
78231743Sgibbs *
79231743Sgibbs * mode
80231743Sgibbs *      Values:         "r" (read only), "w" (writable)
81231743Sgibbs *
82231743Sgibbs *      The read or write access permissions to the backing store to be
83231743Sgibbs *      granted to the frontend.
84231743Sgibbs *
85231743Sgibbs * params
86231743Sgibbs *      Values:         string
87231743Sgibbs *
88231743Sgibbs *      A free formatted string providing sufficient information for the
89231743Sgibbs *      backend driver to open the backing device.  (e.g. the path to the
90231743Sgibbs *      file or block device representing the backing store.)
91231743Sgibbs *
92231743Sgibbs * type
93231743Sgibbs *      Values:         "file", "phy", "tap"
94231743Sgibbs *
95231743Sgibbs *      The type of the backing device/object.
96231743Sgibbs *
97231743Sgibbs *--------------------------------- Features ---------------------------------
98231743Sgibbs *
99231743Sgibbs * feature-barrier
100231743Sgibbs *      Values:         0/1 (boolean)
101231743Sgibbs *      Default Value:  0
102231743Sgibbs *
103231743Sgibbs *      A value of "1" indicates that the backend can process requests
104231743Sgibbs *      containing the BLKIF_OP_WRITE_BARRIER request opcode.  Requests
105231743Sgibbs *      of this type may still be returned at any time with the
106231743Sgibbs *      BLKIF_RSP_EOPNOTSUPP result code.
107231743Sgibbs *
108231743Sgibbs * feature-flush-cache
109231743Sgibbs *      Values:         0/1 (boolean)
110231743Sgibbs *      Default Value:  0
111231743Sgibbs *
112231743Sgibbs *      A value of "1" indicates that the backend can process requests
113231743Sgibbs *      containing the BLKIF_OP_FLUSH_DISKCACHE request opcode.  Requests
114231743Sgibbs *      of this type may still be returned at any time with the
115231743Sgibbs *      BLKIF_RSP_EOPNOTSUPP result code.
116231743Sgibbs *
117231743Sgibbs * feature-discard
118231743Sgibbs *      Values:         0/1 (boolean)
119231743Sgibbs *      Default Value:  0
120231743Sgibbs *
121231743Sgibbs *      A value of "1" indicates that the backend can process requests
122231743Sgibbs *      containing the BLKIF_OP_DISCARD request opcode.  Requests
123231743Sgibbs *      of this type may still be returned at any time with the
124231743Sgibbs *      BLKIF_RSP_EOPNOTSUPP result code.
125231743Sgibbs *
126231743Sgibbs *----------------------- Request Transport Parameters ------------------------
127231743Sgibbs *
128231743Sgibbs * max-ring-page-order
129231743Sgibbs *      Values:         <uint32_t>
130231743Sgibbs *      Default Value:  0
131231743Sgibbs *      Notes:          1, 3
132231743Sgibbs *
133231743Sgibbs *      The maximum supported size of the request ring buffer in units of
134231743Sgibbs *      lb(machine pages). (e.g. 0 == 1 page,  1 = 2 pages, 2 == 4 pages,
135231743Sgibbs *      etc.).
136231743Sgibbs *
137231743Sgibbs * max-ring-pages
138231743Sgibbs *      Values:         <uint32_t>
139231743Sgibbs *      Default Value:  1
140231743Sgibbs *      Notes:          2, 3
141231743Sgibbs *
142231743Sgibbs *      The maximum supported size of the request ring buffer in units of
143231743Sgibbs *      machine pages.  The value must be a power of 2.
144231743Sgibbs *
145231743Sgibbs * max-requests         <uint32_t>
146231743Sgibbs *      Default Value:  BLKIF_MAX_RING_REQUESTS(PAGE_SIZE)
147231743Sgibbs *      Maximum Value:  BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages)
148231743Sgibbs *
149231743Sgibbs *      The maximum number of concurrent, logical requests that will be
150231743Sgibbs *      issued by the backend.
151231743Sgibbs *
152231743Sgibbs *      Note: A logical request may span multiple ring entries.
153231743Sgibbs *
154231743Sgibbs * max-request-segments
155231743Sgibbs *      Values:         <uint8_t>
156231743Sgibbs *      Default Value:  BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK
157231743Sgibbs *      Maximum Value:  BLKIF_MAX_SEGMENTS_PER_REQUEST
158231743Sgibbs *
159231743Sgibbs *      The maximum value of blkif_request.nr_segments supported by
160231743Sgibbs *      the backend.
161231743Sgibbs *
162231743Sgibbs * max-request-size
163231743Sgibbs *      Values:         <uint32_t>
164231743Sgibbs *      Default Value:  BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE
165231743Sgibbs *      Maximum Value:  BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE
166231743Sgibbs *
167231743Sgibbs *      The maximum amount of data, in bytes, that can be referenced by a
168231743Sgibbs *      request type that accesses frontend memory (currently BLKIF_OP_READ,
169231743Sgibbs *      BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER).
170231743Sgibbs *
171231743Sgibbs *------------------------- Backend Device Properties -------------------------
172231743Sgibbs *
173231743Sgibbs * discard-aligment
174231743Sgibbs *      Values:         <uint32_t>
175231743Sgibbs *      Default Value:  0
176231743Sgibbs *      Notes:          4, 5
177231743Sgibbs *
178231743Sgibbs *      The offset, in bytes from the beginning of the virtual block device,
179231743Sgibbs *      to the first, addressable, discard extent on the underlying device.
180231743Sgibbs *
181231743Sgibbs * discard-granularity
182231743Sgibbs *      Values:         <uint32_t>
183231743Sgibbs *      Default Value:  <"sector-size">
184231743Sgibbs *      Notes:          4
185231743Sgibbs *
186231743Sgibbs *      The size, in bytes, of the individually addressable discard extents
187231743Sgibbs *      of the underlying device.
188231743Sgibbs *
189231743Sgibbs * discard-secure
190231743Sgibbs *      Values:         0/1 (boolean)
191231743Sgibbs *      Default Value:  0
192231743Sgibbs *
193231743Sgibbs *      A value of "1" indicates that the backend can process BLKIF_OP_DISCARD
194231743Sgibbs *      requests with the BLKIF_DISCARD_SECURE flag set.
195231743Sgibbs *
196231743Sgibbs * info
197231743Sgibbs *      Values:         <uint32_t> (bitmap)
198231743Sgibbs *
199231743Sgibbs *      A collection of bit flags describing attributes of the backing
200231743Sgibbs *      device.  The VDISK_* macros define the meaning of each bit
201231743Sgibbs *      location.
202231743Sgibbs *
203231743Sgibbs * sector-size
204231743Sgibbs *      Values:         <uint32_t>
205231743Sgibbs *
206231743Sgibbs *      The native sector size, in bytes, of the backend device.
207231743Sgibbs *
208231743Sgibbs * sectors
209231743Sgibbs *      Values:         <uint64_t>
210231743Sgibbs *
211231743Sgibbs *      The size of the backend device, expressed in units of its native
212231743Sgibbs *      sector size ("sector-size").
213231743Sgibbs *
214231743Sgibbs *****************************************************************************
215231743Sgibbs *                            Frontend XenBus Nodes
216231743Sgibbs *****************************************************************************
217231743Sgibbs *
218231743Sgibbs *----------------------- Request Transport Parameters -----------------------
219231743Sgibbs *
220231743Sgibbs * event-channel
221231743Sgibbs *      Values:         <uint32_t>
222231743Sgibbs *
223231743Sgibbs *      The identifier of the Xen event channel used to signal activity
224231743Sgibbs *      in the ring buffer.
225231743Sgibbs *
226231743Sgibbs * ring-ref
227231743Sgibbs *      Values:         <uint32_t>
228231743Sgibbs *      Notes:          6
229231743Sgibbs *
230231743Sgibbs *      The Xen grant reference granting permission for the backend to map
231231743Sgibbs *      the sole page in a single page sized ring buffer.
232231743Sgibbs *
233231743Sgibbs * ring-ref%u
234231743Sgibbs *      Values:         <uint32_t>
235231743Sgibbs *      Notes:          6
236231743Sgibbs *
237231743Sgibbs *      For a frontend providing a multi-page ring, a "num-ring-pages" sized
238231743Sgibbs *      list of nodes, each containing a Xen grant reference granting
239231743Sgibbs *      permission for the backend to map the page of the ring located
240231743Sgibbs *      at page index "%u".  Page indexes are zero based.
241231743Sgibbs *
242231743Sgibbs * protocol
243231743Sgibbs *      Values:         string (XEN_IO_PROTO_ABI_*)
244231743Sgibbs *      Default Value:  XEN_IO_PROTO_ABI_NATIVE
245231743Sgibbs *
246231743Sgibbs *      The machine ABI rules governing the format of all ring request and
247231743Sgibbs *      response structures.
248231743Sgibbs *
249231743Sgibbs * ring-page-order
250231743Sgibbs *      Values:         <uint32_t>
251231743Sgibbs *      Default Value:  0
252231743Sgibbs *      Maximum Value:  MAX(ffs(max-ring-pages) - 1, max-ring-page-order)
253231743Sgibbs *      Notes:          1, 3
254231743Sgibbs *
255231743Sgibbs *      The size of the frontend allocated request ring buffer in units
256231743Sgibbs *      of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
257231743Sgibbs *      etc.).
258231743Sgibbs *
259231743Sgibbs * num-ring-pages
260231743Sgibbs *      Values:         <uint32_t>
261231743Sgibbs *      Default Value:  1
262231743Sgibbs *      Maximum Value:  MAX(max-ring-pages,(0x1 << max-ring-page-order))
263231743Sgibbs *      Notes:          2, 3
264231743Sgibbs *
265231743Sgibbs *      The size of the frontend allocated request ring buffer in units of
266231743Sgibbs *      machine pages.  The value must be a power of 2.
267231743Sgibbs *
268231743Sgibbs * max-requests
269231743Sgibbs *      Values:         <uint32_t>
270231743Sgibbs *      Default Value:  BLKIF_MAX_RING_REQUESTS(PAGE_SIZE)
271231836Sgibbs *      Maximum Value:  BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages)
272231743Sgibbs *
273231743Sgibbs *      The maximum number of concurrent, logical requests that will be
274231743Sgibbs *      issued by the frontend.
275231743Sgibbs *
276231743Sgibbs *      Note: A logical request may span multiple ring entries.
277231743Sgibbs *
278231743Sgibbs * max-request-segments
279231743Sgibbs *      Values:         <uint8_t>
280231743Sgibbs *      Default Value:  BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK
281231743Sgibbs *      Maximum Value:  MIN(255, backend/max-request-segments)
282231743Sgibbs *
283231743Sgibbs *      The maximum value the frontend will set in the
284231743Sgibbs *      blkif_request.nr_segments field.
285231743Sgibbs *
286231743Sgibbs * max-request-size
287231743Sgibbs *      Values:         <uint32_t>
288231743Sgibbs *      Default Value:  BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE
289231743Sgibbs *      Maximum Value:  max-request-segments * PAGE_SIZE
290231743Sgibbs *
291231743Sgibbs *      The maximum amount of data, in bytes, that can be referenced by
292231743Sgibbs *      a request type that accesses frontend memory (currently BLKIF_OP_READ,
293231743Sgibbs *      BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER).
294231743Sgibbs *
295231743Sgibbs *------------------------- Virtual Device Properties -------------------------
296231743Sgibbs *
297231743Sgibbs * device-type
298231743Sgibbs *      Values:         "disk", "cdrom", "floppy", etc.
299231743Sgibbs *
300231743Sgibbs * virtual-device
301231743Sgibbs *      Values:         <uint32_t>
302231743Sgibbs *
303231743Sgibbs *      A value indicating the physical device to virtualize within the
304231743Sgibbs *      frontend's domain.  (e.g. "The first ATA disk", "The third SCSI
305231743Sgibbs *      disk", etc.)
306231743Sgibbs *
307231743Sgibbs *      See docs/misc/vbd-interface.txt for details on the format of this
308231743Sgibbs *      value.
309231743Sgibbs *
310231743Sgibbs * Notes
311231743Sgibbs * -----
312231743Sgibbs * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer
313231743Sgibbs *     PV drivers.
314231743Sgibbs * (2) Multi-page ring buffer scheme first used in some RedHat distributions
315231743Sgibbs *     including a distribution deployed on certain nodes of the Amazon
316231743Sgibbs *     EC2 cluster.
317231743Sgibbs * (3) Support for multi-page ring buffers was implemented independently,
318231743Sgibbs *     in slightly different forms, by both Citrix and RedHat/Amazon.
319231743Sgibbs *     For full interoperability, block front and backends should publish
320231743Sgibbs *     identical ring parameters, adjusted for unit differences, to the
321231743Sgibbs *     XenStore nodes used in both schemes.
322231743Sgibbs * (4) Devices that support discard functionality may internally allocate
323231743Sgibbs *     space (discardable extents) in units that are larger than the
324231743Sgibbs *     exported logical block size.
325231743Sgibbs * (5) The discard-alignment parameter allows a physical device to be
326231743Sgibbs *     partitioned into virtual devices that do not necessarily begin or
327231743Sgibbs *     end on a discardable extent boundary.
328231743Sgibbs * (6) When there is only a single page allocated to the request ring,
329231743Sgibbs *     'ring-ref' is used to communicate the grant reference for this
330231743Sgibbs *     page to the backend.  When using a multi-page ring, the 'ring-ref'
331231743Sgibbs *     node is not created.  Instead 'ring-ref0' - 'ring-refN' are used.
332231743Sgibbs */
333231743Sgibbs
334231743Sgibbs/*
335231743Sgibbs * STATE DIAGRAMS
336231743Sgibbs *
337231743Sgibbs *****************************************************************************
338231743Sgibbs *                                   Startup                                 *
339231743Sgibbs *****************************************************************************
340231743Sgibbs *
341231743Sgibbs * Tool stack creates front and back nodes with state XenbusStateInitialising.
342231743Sgibbs *
343231743Sgibbs * Front                                Back
344231743Sgibbs * =================================    =====================================
345231743Sgibbs * XenbusStateInitialising              XenbusStateInitialising
346231743Sgibbs *  o Query virtual device               o Query backend device identification
347231743Sgibbs *    properties.                          data.
348231743Sgibbs *  o Setup OS device instance.          o Open and validate backend device.
349231743Sgibbs *                                       o Publish backend features and
350231743Sgibbs *                                         transport parameters.
351231743Sgibbs *                                                      |
352231743Sgibbs *                                                      |
353231743Sgibbs *                                                      V
354231743Sgibbs *                                      XenbusStateInitWait
355231743Sgibbs *
356231743Sgibbs * o Query backend features and
357231743Sgibbs *   transport parameters.
358231743Sgibbs * o Allocate and initialize the
359231743Sgibbs *   request ring.
360231743Sgibbs * o Publish transport parameters
361231743Sgibbs *   that will be in effect during
362231743Sgibbs *   this connection.
363231743Sgibbs *              |
364231743Sgibbs *              |
365231743Sgibbs *              V
366231743Sgibbs * XenbusStateInitialised
367231743Sgibbs *
368231743Sgibbs *                                       o Query frontend transport parameters.
369231743Sgibbs *                                       o Connect to the request ring and
370231743Sgibbs *                                         event channel.
371231743Sgibbs *                                       o Publish backend device properties.
372231743Sgibbs *                                                      |
373231743Sgibbs *                                                      |
374231743Sgibbs *                                                      V
375231743Sgibbs *                                      XenbusStateConnected
376231743Sgibbs *
377231743Sgibbs *  o Query backend device properties.
378231743Sgibbs *  o Finalize OS virtual device
379231743Sgibbs *    instance.
380231743Sgibbs *              |
381231743Sgibbs *              |
382231743Sgibbs *              V
383231743Sgibbs * XenbusStateConnected
384231743Sgibbs *
385231743Sgibbs * Note: Drivers that do not support any optional features, or the negotiation
386231743Sgibbs *       of transport parameters, can skip certain states in the state machine:
387231743Sgibbs *
388231743Sgibbs *       o A frontend may transition to XenbusStateInitialised without
389231743Sgibbs *         waiting for the backend to enter XenbusStateInitWait.  In this
390231743Sgibbs *         case, default transport parameters are in effect and any
391231743Sgibbs *         transport parameters published by the frontend must contain
392231743Sgibbs *         their default values.
393231743Sgibbs *
394231743Sgibbs *       o A backend may transition to XenbusStateInitialised, bypassing
395231743Sgibbs *         XenbusStateInitWait, without waiting for the frontend to first
396231743Sgibbs *         enter the XenbusStateInitialised state.  In this case, default
397231743Sgibbs *         transport parameters are in effect and any transport parameters
398231743Sgibbs *         published by the backend must contain their default values.
399231743Sgibbs *
400231743Sgibbs *       Drivers that support optional features and/or transport parameter
401231743Sgibbs *       negotiation must tolerate these additional state transition paths.
402231743Sgibbs *       In general this means performing the work of any skipped state
403231743Sgibbs *       transition, if it has not already been performed, in addition to the
404231743Sgibbs *       work associated with entry into the current state.
405231743Sgibbs */
406231743Sgibbs
407231743Sgibbs/*
408181624Skmacy * REQUEST CODES.
409181624Skmacy */
410181624Skmacy#define BLKIF_OP_READ              0
411181624Skmacy#define BLKIF_OP_WRITE             1
412181624Skmacy/*
413231743Sgibbs * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER
414231743Sgibbs * operation code ("barrier request") must be completed prior to the
415231743Sgibbs * execution of the barrier request.  All writes issued after the barrier
416231743Sgibbs * request must not execute until after the completion of the barrier request.
417231743Sgibbs *
418231743Sgibbs * Optional.  See "feature-barrier" XenBus node documentation above.
419181624Skmacy */
420181624Skmacy#define BLKIF_OP_WRITE_BARRIER     2
421183375Skmacy/*
422231743Sgibbs * Commit any uncommitted contents of the backing device's volatile cache
423231743Sgibbs * to stable storage.
424231743Sgibbs *
425231743Sgibbs * Optional.  See "feature-flush-cache" XenBus node documentation above.
426183375Skmacy */
427183375Skmacy#define BLKIF_OP_FLUSH_DISKCACHE   3
428231743Sgibbs/*
429231743Sgibbs * Used in SLES sources for device specific command packet
430231743Sgibbs * contained within the request. Reserved for that purpose.
431231743Sgibbs */
432231743Sgibbs#define BLKIF_OP_RESERVED_1        4
433231743Sgibbs/*
434231743Sgibbs * Indicate to the backend device that a region of storage is no longer in
435231743Sgibbs * use, and may be discarded at any time without impact to the client.  If
436231743Sgibbs * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the
437231743Sgibbs * discarded region on the device must be rendered unrecoverable before the
438231743Sgibbs * command returns.
439231743Sgibbs *
440231743Sgibbs * This operation is analogous to performing a trim (ATA) or unamp (SCSI),
441231743Sgibbs * command on a native device.
442231743Sgibbs *
443231743Sgibbs * More information about trim/unmap operations can be found at:
444231743Sgibbs * http://t13.org/Documents/UploadedDocuments/docs2008/
445231743Sgibbs *     e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
446231743Sgibbs * http://www.seagate.com/staticfiles/support/disc/manuals/
447231743Sgibbs *     Interface%20manuals/100293068c.pdf
448231743Sgibbs *
449231743Sgibbs * Optional.  See "feature-discard", "discard-alignment",
450231743Sgibbs * "discard-granularity", and "discard-secure" in the XenBus node
451231743Sgibbs * documentation above.
452231743Sgibbs */
453231743Sgibbs#define BLKIF_OP_DISCARD           5
454181624Skmacy
455181624Skmacy/*
456214077Sgibbs * Maximum scatter/gather segments associated with a request header block.
457231743Sgibbs * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
458231743Sgibbs * NB. This could be 12 if the ring indexes weren't stored in the same page.
459181624Skmacy */
460214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK  11
461181624Skmacy
462214077Sgibbs/*
463214077Sgibbs * Maximum scatter/gather segments associated with a segment block.
464214077Sgibbs */
465214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK 14
466214077Sgibbs
467214077Sgibbs/*
468214077Sgibbs * Maximum scatter/gather segments per request (header + segment blocks).
469214077Sgibbs */
470214077Sgibbs#define BLKIF_MAX_SEGMENTS_PER_REQUEST 255
471214077Sgibbs
472231743Sgibbs/*
473231743Sgibbs * NB. first_sect and last_sect in blkif_request_segment, as well as
474231743Sgibbs * sector_number in blkif_request, are always expressed in 512-byte units.
475231743Sgibbs * However they must be properly aligned to the real sector size of the
476231743Sgibbs * physical disk, which is reported in the "sector-size" node in the backend
477231743Sgibbs * xenbus info. Also the xenbus "sectors" node is expressed in 512-byte units.
478231743Sgibbs */
479181624Skmacystruct blkif_request_segment {
480181624Skmacy    grant_ref_t gref;        /* reference to I/O buffer frame        */
481181624Skmacy    /* @first_sect: first sector in frame to transfer (inclusive).   */
482181624Skmacy    /* @last_sect: last sector in frame to transfer (inclusive).     */
483181624Skmacy    uint8_t     first_sect, last_sect;
484181624Skmacy};
485214077Sgibbstypedef struct blkif_request_segment blkif_request_segment_t;
486181624Skmacy
487231743Sgibbs/*
488231743Sgibbs * Starting ring element for any I/O request.
489231743Sgibbs *
490231743Sgibbs * One or more segment blocks can be inserted into the request ring
491231743Sgibbs * just after a blkif_request_t, allowing requests to operate on
492231743Sgibbs * up to BLKIF_MAX_SEGMENTS_PER_REQUEST.
493231743Sgibbs *
494231743Sgibbs * BLKIF_SEGS_TO_BLOCKS() can be used on blkif_requst.nr_segments
495231743Sgibbs * to determine the number of contiguous ring entries associated
496231743Sgibbs * with this request.
497231743Sgibbs *
498231743Sgibbs * Note:  Due to the way Xen request rings operate, the producer and
499231743Sgibbs *        consumer indices of the ring must be incremented by the
500231743Sgibbs *        BLKIF_SEGS_TO_BLOCKS() value of the associated request.
501231743Sgibbs *        (e.g. a response to a 3 ring entry request must also consume
502231743Sgibbs *        3 entries in the ring, even though only the first ring entry
503231743Sgibbs *        in the response has any data.)
504231743Sgibbs */
505181624Skmacystruct blkif_request {
506181624Skmacy    uint8_t        operation;    /* BLKIF_OP_???                         */
507181624Skmacy    uint8_t        nr_segments;  /* number of segments                   */
508181624Skmacy    blkif_vdev_t   handle;       /* only for read/write requests         */
509181624Skmacy    uint64_t       id;           /* private guest value, echoed in resp  */
510181624Skmacy    blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
511231743Sgibbs    blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK];
512181624Skmacy};
513181624Skmacytypedef struct blkif_request blkif_request_t;
514181624Skmacy
515231743Sgibbs/*
516231743Sgibbs * A segment block is a ring request structure that contains only
517231743Sgibbs * segment data.
518231743Sgibbs *
519231743Sgibbs * sizeof(struct blkif_segment_block) <= sizeof(struct blkif_request)
520231743Sgibbs */
521231743Sgibbsstruct blkif_segment_block {
522231743Sgibbs    blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK];
523231743Sgibbs};
524231743Sgibbstypedef struct blkif_segment_block blkif_segment_block_t;
525231743Sgibbs
526231743Sgibbs/*
527231743Sgibbs * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD
528231743Sgibbs * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request)
529231743Sgibbs */
530231743Sgibbsstruct blkif_request_discard {
531231743Sgibbs    uint8_t        operation;    /* BLKIF_OP_DISCARD                     */
532231743Sgibbs    uint8_t        flag;         /* BLKIF_DISCARD_SECURE or zero         */
533231743Sgibbs#define BLKIF_DISCARD_SECURE (1<<0)  /* ignored if discard-secure=0      */
534231743Sgibbs    blkif_vdev_t   handle;       /* same as for read/write requests      */
535231743Sgibbs    uint64_t       id;           /* private guest value, echoed in resp  */
536231743Sgibbs    blkif_sector_t sector_number;/* start sector idx on disk             */
537231743Sgibbs    uint64_t       nr_sectors;   /* number of contiguous sectors to discard*/
538231743Sgibbs};
539231743Sgibbstypedef struct blkif_request_discard blkif_request_discard_t;
540231743Sgibbs
541181624Skmacystruct blkif_response {
542181624Skmacy    uint64_t        id;              /* copied from request */
543181624Skmacy    uint8_t         operation;       /* copied from request */
544181624Skmacy    int16_t         status;          /* BLKIF_RSP_???       */
545181624Skmacy};
546181624Skmacytypedef struct blkif_response blkif_response_t;
547181624Skmacy
548181624Skmacy/*
549181624Skmacy * STATUS RETURN CODES.
550181624Skmacy */
551181624Skmacy /* Operation not supported (only happens on barrier writes). */
552181624Skmacy#define BLKIF_RSP_EOPNOTSUPP  -2
553181624Skmacy /* Operation failed for some unspecified reason (-EIO). */
554181624Skmacy#define BLKIF_RSP_ERROR       -1
555181624Skmacy /* Operation completed successfully. */
556181624Skmacy#define BLKIF_RSP_OKAY         0
557181624Skmacy
558181624Skmacy/*
559181624Skmacy * Generate blkif ring structures and types.
560181624Skmacy */
561181624SkmacyDEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
562181624Skmacy
563231743Sgibbs/*
564231743Sgibbs * Index to, and treat as a segment block, an entry in the ring.
565231743Sgibbs */
566231743Sgibbs#define BLKRING_GET_SEG_BLOCK(_r, _idx)                                 \
567231743Sgibbs    (((blkif_segment_block_t *)RING_GET_REQUEST(_r, _idx))->seg)
568214077Sgibbs
569214077Sgibbs/*
570214077Sgibbs * The number of ring request blocks required to handle an I/O
571214077Sgibbs * request containing _segs segments.
572214077Sgibbs */
573231743Sgibbs#define BLKIF_SEGS_TO_BLOCKS(_segs)                                     \
574231743Sgibbs    ((((_segs - BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK)                    \
575231743Sgibbs     + (BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK - 1))                      \
576231743Sgibbs    / BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK) + /*header_block*/1)
577214077Sgibbs
578231743Sgibbs#define VDISK_CDROM        0x1
579231743Sgibbs#define VDISK_REMOVABLE    0x2
580231743Sgibbs#define VDISK_READONLY     0x4
581231743Sgibbs
582181624Skmacy#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
583181624Skmacy
584181624Skmacy/*
585181624Skmacy * Local variables:
586181624Skmacy * mode: C
587181624Skmacy * c-set-style: "BSD"
588181624Skmacy * c-basic-offset: 4
589181624Skmacy * tab-width: 4
590181624Skmacy * indent-tabs-mode: nil
591181624Skmacy * End:
592181624Skmacy */
593