Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 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) |
Johannes Berg | 27eca5c | 2019-09-11 14:51:22 +0200 | [diff] [blame] | 9 | #define VHOST_USER_FLAG_NEED_REPLY BIT(3) |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 10 | /* Feature bits */ |
| 11 | #define VHOST_USER_F_PROTOCOL_FEATURES 30 |
| 12 | /* Protocol feature bits */ |
Johannes Berg | dd9ada5 | 2020-02-13 14:26:46 +0100 | [diff] [blame] | 13 | #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 |
| 14 | #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 |
| 15 | #define VHOST_USER_PROTOCOL_F_CONFIG 9 |
| 16 | #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 17 | /* Vring state index masks */ |
| 18 | #define VHOST_USER_VRING_INDEX_MASK 0xff |
| 19 | #define VHOST_USER_VRING_POLL_MASK BIT(8) |
| 20 | |
| 21 | /* Supported version */ |
| 22 | #define VHOST_USER_VERSION 1 |
| 23 | /* Supported transport features */ |
| 24 | #define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES) |
| 25 | /* Supported protocol features */ |
Johannes Berg | 27eca5c | 2019-09-11 14:51:22 +0200 | [diff] [blame] | 26 | #define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \ |
| 27 | BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \ |
Johannes Berg | dd9ada5 | 2020-02-13 14:26:46 +0100 | [diff] [blame] | 28 | BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \ |
| 29 | BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS)) |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 30 | |
| 31 | enum vhost_user_request { |
| 32 | VHOST_USER_GET_FEATURES = 1, |
| 33 | VHOST_USER_SET_FEATURES = 2, |
| 34 | VHOST_USER_SET_OWNER = 3, |
| 35 | VHOST_USER_RESET_OWNER = 4, |
| 36 | VHOST_USER_SET_MEM_TABLE = 5, |
| 37 | VHOST_USER_SET_LOG_BASE = 6, |
| 38 | VHOST_USER_SET_LOG_FD = 7, |
| 39 | VHOST_USER_SET_VRING_NUM = 8, |
| 40 | VHOST_USER_SET_VRING_ADDR = 9, |
| 41 | VHOST_USER_SET_VRING_BASE = 10, |
| 42 | VHOST_USER_GET_VRING_BASE = 11, |
| 43 | VHOST_USER_SET_VRING_KICK = 12, |
| 44 | VHOST_USER_SET_VRING_CALL = 13, |
| 45 | VHOST_USER_SET_VRING_ERR = 14, |
| 46 | VHOST_USER_GET_PROTOCOL_FEATURES = 15, |
| 47 | VHOST_USER_SET_PROTOCOL_FEATURES = 16, |
| 48 | VHOST_USER_GET_QUEUE_NUM = 17, |
| 49 | VHOST_USER_SET_VRING_ENABLE = 18, |
| 50 | VHOST_USER_SEND_RARP = 19, |
| 51 | VHOST_USER_NET_SEND_MTU = 20, |
| 52 | VHOST_USER_SET_SLAVE_REQ_FD = 21, |
| 53 | VHOST_USER_IOTLB_MSG = 22, |
| 54 | VHOST_USER_SET_VRING_ENDIAN = 23, |
| 55 | VHOST_USER_GET_CONFIG = 24, |
| 56 | VHOST_USER_SET_CONFIG = 25, |
Johannes Berg | dd9ada5 | 2020-02-13 14:26:46 +0100 | [diff] [blame] | 57 | VHOST_USER_VRING_KICK = 35, |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Johannes Berg | 2cd097b | 2019-09-11 14:51:21 +0200 | [diff] [blame] | 60 | enum vhost_user_slave_request { |
| 61 | VHOST_USER_SLAVE_IOTLB_MSG = 1, |
| 62 | VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, |
| 63 | VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, |
Johannes Berg | dd9ada5 | 2020-02-13 14:26:46 +0100 | [diff] [blame] | 64 | VHOST_USER_SLAVE_VRING_CALL = 4, |
Johannes Berg | 2cd097b | 2019-09-11 14:51:21 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 67 | struct vhost_user_header { |
Johannes Berg | 2cd097b | 2019-09-11 14:51:21 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Use enum vhost_user_request for outgoing messages, |
| 70 | * uses enum vhost_user_slave_request for incoming ones. |
| 71 | */ |
| 72 | u32 request; |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 73 | u32 flags; |
| 74 | u32 size; |
| 75 | } __packed; |
| 76 | |
| 77 | struct vhost_user_config { |
| 78 | u32 offset; |
| 79 | u32 size; |
| 80 | u32 flags; |
Gustavo A. R. Silva | f6e8c47 | 2020-05-07 14:26:52 -0500 | [diff] [blame] | 81 | u8 payload[]; /* Variable length */ |
Erel Geron | 5d38f32 | 2019-09-11 14:51:20 +0200 | [diff] [blame] | 82 | } __packed; |
| 83 | |
| 84 | struct vhost_user_vring_state { |
| 85 | u32 index; |
| 86 | u32 num; |
| 87 | } __packed; |
| 88 | |
| 89 | struct vhost_user_vring_addr { |
| 90 | u32 index; |
| 91 | u32 flags; |
| 92 | u64 desc, used, avail, log; |
| 93 | } __packed; |
| 94 | |
| 95 | struct vhost_user_mem_region { |
| 96 | u64 guest_addr; |
| 97 | u64 size; |
| 98 | u64 user_addr; |
| 99 | u64 mmap_offset; |
| 100 | } __packed; |
| 101 | |
| 102 | struct vhost_user_mem_regions { |
| 103 | u32 num; |
| 104 | u32 padding; |
| 105 | struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */ |
| 106 | } __packed; |
| 107 | |
| 108 | union vhost_user_payload { |
| 109 | u64 integer; |
| 110 | struct vhost_user_config config; |
| 111 | struct vhost_user_vring_state vring_state; |
| 112 | struct vhost_user_vring_addr vring_addr; |
| 113 | struct vhost_user_mem_regions mem_regions; |
| 114 | }; |
| 115 | |
| 116 | struct vhost_user_msg { |
| 117 | struct vhost_user_header header; |
| 118 | union vhost_user_payload payload; |
| 119 | } __packed; |
| 120 | |
| 121 | #endif |