xref: /onnv-gate/usr/src/uts/common/xen/io/blkif_impl.h (revision 7756:d653ef0c7180)
16144Srab /*
26144Srab  * Permission is hereby granted, free of charge, to any person obtaining a copy
36144Srab  * of this software and associated documentation files (the "Software"), to
46144Srab  * deal in the Software without restriction, including without limitation the
56144Srab  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
66144Srab  * sell copies of the Software, and to permit persons to whom the Software is
76144Srab  * furnished to do so, subject to the following conditions:
86144Srab  *
96144Srab  * The above copyright notice and this permission notice shall be included in
106144Srab  * all copies or substantial portions of the Software.
116144Srab  *
126144Srab  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136144Srab  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
146144Srab  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
156144Srab  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
166144Srab  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
176144Srab  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
186144Srab  * DEALINGS IN THE SOFTWARE.
196144Srab  */
206144Srab #ifndef __XEN_BLKIF_H__
216144Srab #define __XEN_BLKIF_H__
226144Srab 
236144Srab #include <public/io/ring.h>
246144Srab #include <public/io/blkif.h>
256144Srab #include <public/io/protocols.h>
266144Srab 
276144Srab /* Not a real protocol.  Used to generate ring structs which contain
286144Srab  * the elements common to all protocols only.  This way we get a
296144Srab  * compiler-checkable way to use common struct elements, so we can
306144Srab  * avoid using switch(protocol) in a number of places.  */
316144Srab 
326144Srab /* i386 protocol version */
336144Srab 
346144Srab #pragma pack(4)
356144Srab 
366144Srab struct blkif_x86_32_request {
376144Srab 	uint8_t        operation;    /* BLKIF_OP_???                         */
386144Srab 	uint8_t        nr_segments;  /* number of segments                   */
396144Srab 	blkif_vdev_t   handle;       /* only for read/write requests         */
406144Srab 	uint64_t       id;           /* private guest value, echoed in resp  */
416144Srab 	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
426144Srab 	struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
436144Srab };
446144Srab struct blkif_x86_32_response {
456144Srab 	uint64_t        id;              /* copied from request */
466144Srab 	uint8_t         operation;       /* copied from request */
476144Srab 	int16_t         status;          /* BLKIF_RSP_???       */
486144Srab };
496144Srab typedef struct blkif_x86_32_request blkif_x86_32_request_t;
506144Srab typedef struct blkif_x86_32_response blkif_x86_32_response_t;
516144Srab 
526144Srab #pragma pack()
536144Srab 
546144Srab /* x86_64 protocol version */
556144Srab struct blkif_x86_64_request {
566144Srab 	uint8_t        operation;    /* BLKIF_OP_???                         */
576144Srab 	uint8_t        nr_segments;  /* number of segments                   */
586144Srab 	blkif_vdev_t   handle;       /* only for read/write requests         */
596144Srab #if defined(__GNUC__)
606144Srab 	uint64_t       __attribute__((__aligned__(8))) id;
616144Srab #else
626144Srab 	uint8_t        pad[4];
636144Srab 	uint64_t       id;
646144Srab #endif
656144Srab 	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
666144Srab 	struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
676144Srab };
686144Srab struct blkif_x86_64_response {
696144Srab #if defined(__GNUC__)
706144Srab 	uint64_t       __attribute__((__aligned__(8))) id;
716144Srab #else
726144Srab 	uint64_t       id;
736144Srab #endif
746144Srab 	uint8_t         operation;       /* copied from request */
756144Srab 	int16_t         status;          /* BLKIF_RSP_???       */
766144Srab };
776144Srab typedef struct blkif_x86_64_request blkif_x86_64_request_t;
786144Srab typedef struct blkif_x86_64_response blkif_x86_64_response_t;
796144Srab 
806144Srab DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
816144Srab DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
826144Srab 
836144Srab enum blkif_protocol {
846144Srab 	BLKIF_PROTOCOL_NATIVE = 1,
856144Srab 	BLKIF_PROTOCOL_X86_32 = 2,
866144Srab 	BLKIF_PROTOCOL_X86_64 = 3,
876144Srab };
886144Srab 
89*7756SMark.Johnson@Sun.COM #define	BLKIF_RING_SIZE	\
90*7756SMark.Johnson@Sun.COM 	__RING_SIZE((blkif_sring_t *)NULL, PAGESIZE)
91*7756SMark.Johnson@Sun.COM #define	BLKIF_X86_32_RING_SIZE \
92*7756SMark.Johnson@Sun.COM 	__RING_SIZE((blkif_x86_32_sring_t *)NULL, PAGESIZE)
93*7756SMark.Johnson@Sun.COM #define	BLKIF_X86_64_RING_SIZE \
94*7756SMark.Johnson@Sun.COM 	__RING_SIZE((blkif_x86_64_sring_t *)NULL, PAGESIZE)
95*7756SMark.Johnson@Sun.COM 
966144Srab #endif /* __XEN_BLKIF_H__ */
97