1/* $NetBSD: xenring.h,v 1.7 2023/02/25 00:32:26 riastradh Exp $ */ 2 3/* 4 * Glue goop for xbd ring request/response protocol structures. 5 * 6 * These are used only from __XEN_INTERFACE_VERSION__ >= 0x00030201 7 * prior to which they were part of the public XEN api. 8 */ 9 10#ifndef _XEN_RING_H 11#define _XEN_RING_H 12 13#if (__XEN_INTERFACE_VERSION__ >= 0x00030201) && \ 14 (__XEN_INTERFACE_VERSION < 0x00030208) 15 16#include <xen/include/public/io/ring.h> 17 18/* 19 * Undo namespace damage from xen/include/public/io/ring.h 20 * The proper fix is to get upstream to stop assuming that all OSs use 21 * mb(), rmb(), wmb(). 22 */ 23#undef xen_mb 24#undef xen_rmb 25#undef xen_wmb 26 27#define xen_mb() membar_sync() 28#define xen_rmb() membar_acquire() 29#define xen_wmb() membar_release() 30 31/* 32 * Define ring types. These were previously part of the public API. 33 * Not anymore. 34 */ 35/* i386 requests/responses */ 36struct blkif_x86_32_request { 37 uint8_t operation; /* BLKIF_OP_??? */ 38 uint8_t nr_segments; /* number of segments */ 39 blkif_vdev_t handle; /* only for read/write requests */ 40 uint64_t id; /* private guest value, echoed in resp */ 41 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 42 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 43} __packed; 44typedef struct blkif_x86_32_request blkif_x86_32_request_t; 45 46struct blkif_x86_32_response { 47 uint64_t id; /* copied from request */ 48 uint8_t operation; /* copied from request */ 49 uint8_t _pad; 50 int16_t status; /* BLKIF_RSP_??? */ 51} __packed; 52typedef struct blkif_x86_32_response blkif_x86_32_response_t; 53 54struct blkif_x86_32_request_indirect { 55 uint8_t operation; /* BLKIF_OP_INDIRECT */ 56 uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */ 57 uint16_t nr_segments; /* number of segments */ 58 uint64_t id; /* private guest value, echoed in resp */ 59 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 60 blkif_vdev_t handle; /* only for read/write requests */ 61 uint16_t _pad2; 62 grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST]; 63 uint64_t _pad3; /* make it 64 byte aligned */ 64} __packed; 65typedef struct blkif_x86_32_request_indirect blkif_x86_32_request_indirect_t; 66 67/* amd64-type requests/responses (always used in frontends ) */ 68 69struct blkif_x86_64_request { 70 uint8_t operation; /* BLKIF_OP_??? */ 71 uint8_t nr_segments; /* number of segments */ 72 blkif_vdev_t handle; /* only for read/write requests */ 73 uint64_t __attribute__((__aligned__(8))) id;/* private guest value, echoed in resp */ 74 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 75 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 76}; 77typedef struct blkif_x86_64_request blkif_x86_64_request_t; 78 79struct blkif_x86_64_response { 80 uint64_t __attribute__((__aligned__(8))) id; /* copied from request */ 81 uint8_t operation; /* copied from request */ 82 int16_t status; /* BLKIF_RSP_??? */ 83}; 84typedef struct blkif_x86_64_response blkif_x86_64_response_t; 85 86struct blkif_x86_64_request_indirect { 87 uint8_t operation; /* BLKIF_OP_INDIRECT */ 88 uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */ 89 uint16_t nr_segments; /* number of segments */ 90 uint32_t _pad1; 91 uint64_t id; /* private guest value, echoed in resp */ 92 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 93 blkif_vdev_t handle; /* only for read/write requests */ 94 uint16_t _pad2; 95 grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST]; 96 uint32_t _pad3; /* make it 64 byte aligned */ 97} __packed; 98typedef struct blkif_x86_64_request_indirect blkif_x86_64_request_indirect_t; 99 100CTASSERT(sizeof(struct blkif_x86_32_request_indirect) 101 == sizeof(struct blkif_x86_64_request_indirect)); 102CTASSERT(sizeof(struct blkif_request_indirect) 103 == sizeof(struct blkif_x86_64_request_indirect)); 104 105DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response); 106DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response); 107 108union blkif_back_ring_proto { 109 blkif_back_ring_t ring_n; /* native/common members */ 110 blkif_x86_32_back_ring_t ring_32; 111 blkif_x86_64_back_ring_t ring_64; 112}; 113typedef union blkif_back_ring_proto blkif_back_ring_proto_t; 114 115#endif /* __XEN_INTERFACE_VERSION__ */ 116 117#endif /* _XEN_RING_H_ */ 118