xref: /illumos-gate/usr/src/uts/common/xen/io/blkif_impl.h (revision 55fea89d)
1*55fea89dSDan Cross /*
2a576ab5bSrab  * Permission is hereby granted, free of charge, to any person obtaining a copy
3a576ab5bSrab  * of this software and associated documentation files (the "Software"), to
4a576ab5bSrab  * deal in the Software without restriction, including without limitation the
5a576ab5bSrab  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6a576ab5bSrab  * sell copies of the Software, and to permit persons to whom the Software is
7a576ab5bSrab  * furnished to do so, subject to the following conditions:
8a576ab5bSrab  *
9a576ab5bSrab  * The above copyright notice and this permission notice shall be included in
10a576ab5bSrab  * all copies or substantial portions of the Software.
11a576ab5bSrab  *
12a576ab5bSrab  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13a576ab5bSrab  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14a576ab5bSrab  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15a576ab5bSrab  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16a576ab5bSrab  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17a576ab5bSrab  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18a576ab5bSrab  * DEALINGS IN THE SOFTWARE.
19a576ab5bSrab  */
20a576ab5bSrab #ifndef __XEN_BLKIF_H__
21a576ab5bSrab #define __XEN_BLKIF_H__
22a576ab5bSrab 
23a576ab5bSrab #include <public/io/ring.h>
24a576ab5bSrab #include <public/io/blkif.h>
25a576ab5bSrab #include <public/io/protocols.h>
26a576ab5bSrab 
27a576ab5bSrab /* Not a real protocol.  Used to generate ring structs which contain
28a576ab5bSrab  * the elements common to all protocols only.  This way we get a
29a576ab5bSrab  * compiler-checkable way to use common struct elements, so we can
30a576ab5bSrab  * avoid using switch(protocol) in a number of places.  */
31a576ab5bSrab 
32a576ab5bSrab /* i386 protocol version */
33a576ab5bSrab 
34a576ab5bSrab #pragma pack(4)
35a576ab5bSrab 
36a576ab5bSrab struct blkif_x86_32_request {
37a576ab5bSrab 	uint8_t        operation;    /* BLKIF_OP_???                         */
38a576ab5bSrab 	uint8_t        nr_segments;  /* number of segments                   */
39a576ab5bSrab 	blkif_vdev_t   handle;       /* only for read/write requests         */
40a576ab5bSrab 	uint64_t       id;           /* private guest value, echoed in resp  */
41a576ab5bSrab 	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
42a576ab5bSrab 	struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
43a576ab5bSrab };
44a576ab5bSrab struct blkif_x86_32_response {
45a576ab5bSrab 	uint64_t        id;              /* copied from request */
46a576ab5bSrab 	uint8_t         operation;       /* copied from request */
47a576ab5bSrab 	int16_t         status;          /* BLKIF_RSP_???       */
48a576ab5bSrab };
49a576ab5bSrab typedef struct blkif_x86_32_request blkif_x86_32_request_t;
50a576ab5bSrab typedef struct blkif_x86_32_response blkif_x86_32_response_t;
51a576ab5bSrab 
52a576ab5bSrab #pragma pack()
53a576ab5bSrab 
54a576ab5bSrab /* x86_64 protocol version */
55a576ab5bSrab struct blkif_x86_64_request {
56a576ab5bSrab 	uint8_t        operation;    /* BLKIF_OP_???                         */
57a576ab5bSrab 	uint8_t        nr_segments;  /* number of segments                   */
58a576ab5bSrab 	blkif_vdev_t   handle;       /* only for read/write requests         */
59a576ab5bSrab #if defined(__GNUC__)
60a576ab5bSrab 	uint64_t       __attribute__((__aligned__(8))) id;
61a576ab5bSrab #else
62a576ab5bSrab 	uint8_t        pad[4];
63a576ab5bSrab 	uint64_t       id;
64a576ab5bSrab #endif
65a576ab5bSrab 	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
66a576ab5bSrab 	struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
67a576ab5bSrab };
68a576ab5bSrab struct blkif_x86_64_response {
69a576ab5bSrab #if defined(__GNUC__)
70a576ab5bSrab 	uint64_t       __attribute__((__aligned__(8))) id;
71a576ab5bSrab #else
72a576ab5bSrab 	uint64_t       id;
73a576ab5bSrab #endif
74a576ab5bSrab 	uint8_t         operation;       /* copied from request */
75a576ab5bSrab 	int16_t         status;          /* BLKIF_RSP_???       */
76a576ab5bSrab };
77a576ab5bSrab typedef struct blkif_x86_64_request blkif_x86_64_request_t;
78a576ab5bSrab typedef struct blkif_x86_64_response blkif_x86_64_response_t;
79a576ab5bSrab 
80a576ab5bSrab DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
81a576ab5bSrab DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
82a576ab5bSrab 
83a576ab5bSrab enum blkif_protocol {
84a576ab5bSrab 	BLKIF_PROTOCOL_NATIVE = 1,
85a576ab5bSrab 	BLKIF_PROTOCOL_X86_32 = 2,
86a576ab5bSrab 	BLKIF_PROTOCOL_X86_64 = 3,
87a576ab5bSrab };
88a576ab5bSrab 
897eea693dSMark Johnson #define	BLKIF_RING_SIZE	\
907eea693dSMark Johnson 	__RING_SIZE((blkif_sring_t *)NULL, PAGESIZE)
917eea693dSMark Johnson #define	BLKIF_X86_32_RING_SIZE \
927eea693dSMark Johnson 	__RING_SIZE((blkif_x86_32_sring_t *)NULL, PAGESIZE)
937eea693dSMark Johnson #define	BLKIF_X86_64_RING_SIZE \
947eea693dSMark Johnson 	__RING_SIZE((blkif_x86_64_sring_t *)NULL, PAGESIZE)
957eea693dSMark Johnson 
96a576ab5bSrab #endif /* __XEN_BLKIF_H__ */
97