|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* Vhost-user protocol */ |
| 3 | + |
| 4 | +#ifndef __VHOST_USER_H__ |
| 5 | +#define __VHOST_USER_H__ |
| 6 | + |
| 7 | +/* Message flags */ |
| 8 | +#define VHOST_USER_FLAG_REPLY BIT(2) |
| 9 | +/* Feature bits */ |
| 10 | +#define VHOST_USER_F_PROTOCOL_FEATURES 30 |
| 11 | +/* Protocol feature bits */ |
| 12 | +#define VHOST_USER_PROTOCOL_F_CONFIG 9 |
| 13 | +/* Vring state index masks */ |
| 14 | +#define VHOST_USER_VRING_INDEX_MASK 0xff |
| 15 | +#define VHOST_USER_VRING_POLL_MASK BIT(8) |
| 16 | + |
| 17 | +/* Supported version */ |
| 18 | +#define VHOST_USER_VERSION 1 |
| 19 | +/* Supported transport features */ |
| 20 | +#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES) |
| 21 | +/* Supported protocol features */ |
| 22 | +#define VHOST_USER_SUPPORTED_PROTOCOL_F BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) |
| 23 | + |
| 24 | +enum vhost_user_request { |
| 25 | + VHOST_USER_GET_FEATURES = 1, |
| 26 | + VHOST_USER_SET_FEATURES = 2, |
| 27 | + VHOST_USER_SET_OWNER = 3, |
| 28 | + VHOST_USER_RESET_OWNER = 4, |
| 29 | + VHOST_USER_SET_MEM_TABLE = 5, |
| 30 | + VHOST_USER_SET_LOG_BASE = 6, |
| 31 | + VHOST_USER_SET_LOG_FD = 7, |
| 32 | + VHOST_USER_SET_VRING_NUM = 8, |
| 33 | + VHOST_USER_SET_VRING_ADDR = 9, |
| 34 | + VHOST_USER_SET_VRING_BASE = 10, |
| 35 | + VHOST_USER_GET_VRING_BASE = 11, |
| 36 | + VHOST_USER_SET_VRING_KICK = 12, |
| 37 | + VHOST_USER_SET_VRING_CALL = 13, |
| 38 | + VHOST_USER_SET_VRING_ERR = 14, |
| 39 | + VHOST_USER_GET_PROTOCOL_FEATURES = 15, |
| 40 | + VHOST_USER_SET_PROTOCOL_FEATURES = 16, |
| 41 | + VHOST_USER_GET_QUEUE_NUM = 17, |
| 42 | + VHOST_USER_SET_VRING_ENABLE = 18, |
| 43 | + VHOST_USER_SEND_RARP = 19, |
| 44 | + VHOST_USER_NET_SEND_MTU = 20, |
| 45 | + VHOST_USER_SET_SLAVE_REQ_FD = 21, |
| 46 | + VHOST_USER_IOTLB_MSG = 22, |
| 47 | + VHOST_USER_SET_VRING_ENDIAN = 23, |
| 48 | + VHOST_USER_GET_CONFIG = 24, |
| 49 | + VHOST_USER_SET_CONFIG = 25, |
| 50 | +}; |
| 51 | + |
| 52 | +struct vhost_user_header { |
| 53 | + u32 request; /* Use enum vhost_user_request */ |
| 54 | + u32 flags; |
| 55 | + u32 size; |
| 56 | +} __packed; |
| 57 | + |
| 58 | +struct vhost_user_config { |
| 59 | + u32 offset; |
| 60 | + u32 size; |
| 61 | + u32 flags; |
| 62 | + u8 payload[0]; /* Variable length */ |
| 63 | +} __packed; |
| 64 | + |
| 65 | +struct vhost_user_vring_state { |
| 66 | + u32 index; |
| 67 | + u32 num; |
| 68 | +} __packed; |
| 69 | + |
| 70 | +struct vhost_user_vring_addr { |
| 71 | + u32 index; |
| 72 | + u32 flags; |
| 73 | + u64 desc, used, avail, log; |
| 74 | +} __packed; |
| 75 | + |
| 76 | +struct vhost_user_mem_region { |
| 77 | + u64 guest_addr; |
| 78 | + u64 size; |
| 79 | + u64 user_addr; |
| 80 | + u64 mmap_offset; |
| 81 | +} __packed; |
| 82 | + |
| 83 | +struct vhost_user_mem_regions { |
| 84 | + u32 num; |
| 85 | + u32 padding; |
| 86 | + struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */ |
| 87 | +} __packed; |
| 88 | + |
| 89 | +union vhost_user_payload { |
| 90 | + u64 integer; |
| 91 | + struct vhost_user_config config; |
| 92 | + struct vhost_user_vring_state vring_state; |
| 93 | + struct vhost_user_vring_addr vring_addr; |
| 94 | + struct vhost_user_mem_regions mem_regions; |
| 95 | +}; |
| 96 | + |
| 97 | +struct vhost_user_msg { |
| 98 | + struct vhost_user_header header; |
| 99 | + union vhost_user_payload payload; |
| 100 | +} __packed; |
| 101 | + |
| 102 | +#endif |
0 commit comments