1a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/******************************************************************************
2a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * blkif.h
3a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge *
4a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Unified block-device I/O interface for Xen guest OSes.
5a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge *
6a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Copyright (c) 2003-2004, Keir Fraser
7a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
8a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
9a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#ifndef __XEN_PUBLIC_IO_BLKIF_H__
10a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define __XEN_PUBLIC_IO_BLKIF_H__
11a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
12a1ce39288e6fbefdd8d607021d02384eb4a20b99David Howells#include <xen/interface/io/ring.h>
13a1ce39288e6fbefdd8d607021d02384eb4a20b99David Howells#include <xen/interface/grant_table.h>
14a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
15a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
16a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Front->back notifications: When enqueuing a new request, sending a
17a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * notification can be made conditional on req_event (i.e., the generic
18a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * hold-off mechanism provided by the ring macros). Backends must set
19a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
20a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge *
21a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Back->front notifications: When enqueuing a new response, sending a
22a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * notification can be made conditional on rsp_event (i.e., the generic
23a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * hold-off mechanism provided by the ring macros). Frontends must set
24a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
25a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
26a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
27a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardingetypedef uint16_t blkif_vdev_t;
28a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardingetypedef uint64_t blkif_sector_t;
29a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
30a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
31a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * REQUEST CODES.
32a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
33a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_OP_READ              0
34a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_OP_WRITE             1
35a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
36a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Recognised only if "feature-barrier" is present in backend xenbus info.
37a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * The "feature_barrier" node contains a boolean indicating whether barrier
38a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * requests are likely to succeed or fail. Either way, a barrier request
39a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
40a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * the underlying block-device hardware. The boolean simply indicates whether
41a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * or not it is worthwhile for the frontend to attempt barrier requests.
42a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*
43a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * create the "feature-barrier" node!
44a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
45a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_OP_WRITE_BARRIER     2
46a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
47a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
486dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * Recognised if "feature-flush-cache" is present in backend xenbus
496dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * info.  A flush will ask the underlying storage hardware to flush its
506dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * non-volatile caches as appropriate.  The "feature-flush-cache" node
516dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * contains a boolean indicating whether flush requests are likely to
526dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * succeed or fail. Either way, a flush request may fail at any time
536dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * with BLKIF_RSP_EOPNOTSUPP if it is unsupported by the underlying
546dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * block-device hardware. The boolean simply indicates whether or not it
556dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * is worthwhile for the frontend to attempt flushes.  If a backend does
566dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * not recognise BLKIF_OP_WRITE_FLUSH_CACHE, it should *not* create the
576dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk * "feature-flush-cache" node!
586dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk */
596dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk#define BLKIF_OP_FLUSH_DISKCACHE   3
6032a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang
6132a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang/*
6232a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * Recognised only if "feature-discard" is present in backend xenbus info.
6332a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * The "feature-discard" node contains a boolean indicating whether trim
6432a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * (ATA) or unmap (SCSI) - conviently called discard requests are likely
6532a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * to succeed or fail. Either way, a discard request
6632a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
6732a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * the underlying block-device hardware. The boolean simply indicates whether
6832a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * or not it is worthwhile for the frontend to attempt discard requests.
6932a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * If a backend does not recognise BLKIF_OP_DISCARD, it should *not*
7032a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * create the "feature-discard" node!
7132a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang *
7232a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * Discard operation is a request for the underlying block device to mark
7332a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * extents to be erased. However, discard does not guarantee that the blocks
7432a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * will be erased from the device - it is just a hint to the device
7532a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * controller that these blocks are no longer in use. What the device
7632a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * controller does with that information is left to the controller.
7732a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * Discard operations are passed with sector_number as the
7832a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * sector index to begin discard operations at and nr_sectors as the number of
7932a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * sectors to be discarded. The specified sectors should be discarded if the
8032a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * underlying block device supports trim (ATA) or unmap (SCSI) operations,
8132a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * or a BLKIF_RSP_EOPNOTSUPP  should be returned.
8232a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * More information about trim/unmap operations at:
8332a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * http://t13.org/Documents/UploadedDocuments/docs2008/
8432a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang *     e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
8532a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang * http://www.seagate.com/staticfiles/support/disc/manuals/
8632a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang *     Interface%20manuals/100293068c.pdf
875ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * The backend can optionally provide three extra XenBus attributes to
885ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * further optimize the discard functionality:
891c339ef74b431bab18bc11fb69e46db294070dd3Olaf Hering * 'discard-alignment' - Devices that support discard functionality may
905ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * internally allocate space in units that are bigger than the exported
915ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * logical block size. The discard-alignment parameter indicates how many bytes
925ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * the beginning of the partition is offset from the internal allocation unit's
935ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * natural alignment.
945ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * 'discard-granularity'  - Devices that support discard functionality may
955ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * internally allocate space using units that are bigger than the logical block
965ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * size. The discard-granularity parameter indicates the size of the internal
975ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * allocation unit in bytes if reported by the device. Otherwise the
985ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * discard-granularity will be set to match the device's physical block size.
995ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * 'discard-secure' - All copies of the discarded sectors (potentially created
1005ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * by garbage collection) must also be erased.  To use this feature, the flag
1015ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk * BLKIF_DISCARD_SECURE must be set in the blkif_request_trim.
10232a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang */
10332a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang#define BLKIF_OP_DISCARD           5
10432a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang
1056dcfb751c927879399e404b3885cbdef7d8d368bKonrad Rzeszutek Wilk/*
106402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * Recognized if "feature-max-indirect-segments" in present in the backend
107402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * xenbus info. The "feature-max-indirect-segments" node contains the maximum
108402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * number of segments allowed by the backend per request. If the node is
109402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * present, the frontend might use blkif_request_indirect structs in order to
110402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The
111402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * maximum number of indirect segments is fixed by the backend, but the
112402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * frontend can issue requests with any number of indirect segments as long as
113402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * it's less than the number provided by the backend. The indirect_grefs field
114402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * in blkif_request_indirect should be filled by the frontend with the
115402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * grant references of the pages that are holding the indirect segments.
11680bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * These pages are filled with an array of blkif_request_segment that hold the
11780bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * information about the segments. The number of indirect pages to use is
11880bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * determined by the number of segments an indirect request contains. Every
11980bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * indirect page can contain a maximum of
12080bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
12180bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * calculate the number of indirect pages to use we have to do
12280bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
123402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne *
124402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
125402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne * create the "feature-max-indirect-segments" node!
126402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne */
127402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne#define BLKIF_OP_INDIRECT          6
128402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne
129402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne/*
130a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Maximum scatter/gather segments per request.
131a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.
132a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * NB. This could be 12 if the ring indexes weren't stored in the same page.
133a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
134a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
135a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
136402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
137402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne
13880bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monnestruct blkif_request_segment {
13980bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne		grant_ref_t gref;        /* reference to I/O buffer frame        */
14080bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne		/* @first_sect: first sector in frame to transfer (inclusive).   */
14180bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne		/* @last_sect: last sector in frame to transfer (inclusive).     */
14280bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne		uint8_t     first_sect, last_sect;
14380bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne};
144402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne
14551de69523ffe1c17994dc2f260369f29dfdce71cOwen Smithstruct blkif_request_rw {
14697e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint8_t        nr_segments;  /* number of segments                   */
14797e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	blkif_vdev_t   handle;       /* only for read/write requests         */
148380108d891acf8db5cf0d477176c7ed2b62b7928Julien Grall#ifndef CONFIG_X86_32
14997e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint32_t       _pad1;	     /* offsetof(blkif_request,u.rw.id) == 8 */
15097e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk#endif
15197e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint64_t       id;           /* private guest value, echoed in resp  */
152a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
15380bfa2f6e2e81049fc6cd3bfaeedcb64db3a9ba6Roger Pau Monne	struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
15497e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk} __attribute__((__packed__));
155a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
15632a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyangstruct blkif_request_discard {
1575ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk	uint8_t        flag;         /* BLKIF_DISCARD_SECURE or zero.        */
1585ea42986694a96542644f9cae8b122d3a00c508fKonrad Rzeszutek Wilk#define BLKIF_DISCARD_SECURE (1<<0)  /* ignored if discard-secure=0          */
15997e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	blkif_vdev_t   _pad1;        /* only for read/write requests         */
160380108d891acf8db5cf0d477176c7ed2b62b7928Julien Grall#ifndef CONFIG_X86_32
16197e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint32_t       _pad2;        /* offsetof(blkif_req..,u.discard.id)==8*/
16297e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk#endif
16397e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint64_t       id;           /* private guest value, echoed in resp  */
16432a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang	blkif_sector_t sector_number;
16597e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint64_t       nr_sectors;
16697e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk	uint8_t        _pad3;
16797e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk} __attribute__((__packed__));
16832a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang
1690e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabelstruct blkif_request_other {
1700e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel	uint8_t      _pad1;
1710e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel	blkif_vdev_t _pad2;        /* only for read/write requests         */
172380108d891acf8db5cf0d477176c7ed2b62b7928Julien Grall#ifndef CONFIG_X86_32
1730e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel	uint32_t     _pad3;        /* offsetof(blkif_req..,u.other.id)==8*/
1740e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel#endif
1750e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel	uint64_t     id;           /* private guest value, echoed in resp  */
1760e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel} __attribute__((__packed__));
1770e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel
178402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monnestruct blkif_request_indirect {
179402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint8_t        indirect_op;
180402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint16_t       nr_segments;
181380108d891acf8db5cf0d477176c7ed2b62b7928Julien Grall#ifndef CONFIG_X86_32
182402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint32_t       _pad1;        /* offsetof(blkif_...,u.indirect.id) == 8 */
183402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne#endif
184402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint64_t       id;
185402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	blkif_sector_t sector_number;
186402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	blkif_vdev_t   handle;
187402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint16_t       _pad2;
188402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	grant_ref_t    indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
189380108d891acf8db5cf0d477176c7ed2b62b7928Julien Grall#ifndef CONFIG_X86_32
190402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint32_t      _pad3;         /* make it 64 byte aligned */
191402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne#else
192402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne	uint64_t      _pad3;         /* make it 64 byte aligned */
193402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne#endif
194402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne} __attribute__((__packed__));
195402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne
19651de69523ffe1c17994dc2f260369f29dfdce71cOwen Smithstruct blkif_request {
19751de69523ffe1c17994dc2f260369f29dfdce71cOwen Smith	uint8_t        operation;    /* BLKIF_OP_???                         */
19851de69523ffe1c17994dc2f260369f29dfdce71cOwen Smith	union {
19951de69523ffe1c17994dc2f260369f29dfdce71cOwen Smith		struct blkif_request_rw rw;
20032a8d26cc9b96629269e04ee6c583e14398f6f47Li Dongyang		struct blkif_request_discard discard;
2010e367ae46503cfe7791460c8ba8434a5d60b2bd5David Vrabel		struct blkif_request_other other;
202402b27f9f2c22309d5bb285628765bc27b82fcf5Roger Pau Monne		struct blkif_request_indirect indirect;
20351de69523ffe1c17994dc2f260369f29dfdce71cOwen Smith	} u;
20497e36834f5a106459ab1b290e663a4eb6264639eKonrad Rzeszutek Wilk} __attribute__((__packed__));
20551de69523ffe1c17994dc2f260369f29dfdce71cOwen Smith
206a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardingestruct blkif_response {
207a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge	uint64_t        id;              /* copied from request */
208a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge	uint8_t         operation;       /* copied from request */
209a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge	int16_t         status;          /* BLKIF_RSP_???       */
210a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge};
211a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
212a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
213a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * STATUS RETURN CODES.
214a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
215a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge /* Operation not supported (only happens on barrier writes). */
216a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_RSP_EOPNOTSUPP  -2
217a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge /* Operation failed for some unspecified reason (-EIO). */
218a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_RSP_ERROR       -1
219a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge /* Operation completed successfully. */
220a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define BLKIF_RSP_OKAY         0
221a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
222a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge/*
223a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge * Generate blkif ring structures and types.
224a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge */
225a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
226a42089dd358a7673a0a23126589a9029e57c2049Jeremy FitzhardingeDEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
227a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
228a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define VDISK_CDROM        0x1
229a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define VDISK_REMOVABLE    0x2
230a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#define VDISK_READONLY     0x4
231a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge
232c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini/* Xen-defined major numbers for virtual disks, they look strangely
233c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini * familiar */
234c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_IDE0_MAJOR	3
235c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_IDE1_MAJOR	22
236c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK0_MAJOR	8
237c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK1_MAJOR	65
238c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK2_MAJOR	66
239c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK3_MAJOR	67
240c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK4_MAJOR	68
241c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK5_MAJOR	69
242c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK6_MAJOR	70
243c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK7_MAJOR	71
244c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK8_MAJOR	128
245c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK9_MAJOR	129
246c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK10_MAJOR	130
247c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK11_MAJOR	131
248c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK12_MAJOR	132
249c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK13_MAJOR	133
250c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK14_MAJOR	134
251c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini#define XEN_SCSI_DISK15_MAJOR	135
252c80a420995e721099906607b07c09a24543b31d9Stefano Stabellini
253a42089dd358a7673a0a23126589a9029e57c2049Jeremy Fitzhardinge#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
254