1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2018, Microsoft Corporation. 3 * All Rights Reserved. 4 */ 5 6 #ifndef _VMBUS_REG_H_ 7 #define _VMBUS_REG_H_ 8 9 /* 10 * Hyper-V SynIC message format. 11 */ 12 #define VMBUS_MSG_DSIZE_MAX 240 13 #define VMBUS_MSG_SIZE 256 14 15 struct vmbus_message { 16 uint32_t type; /* HYPERV_MSGTYPE_ */ 17 uint8_t dsize; /* data size */ 18 uint8_t flags; /* VMBUS_MSGFLAG_ */ 19 uint16_t rsvd; 20 uint64_t id; 21 uint8_t data[VMBUS_MSG_DSIZE_MAX]; 22 } __rte_packed; 23 24 #define VMBUS_MSGFLAG_PENDING 0x01 25 26 /* 27 * Hyper-V Monitor Notification Facility 28 */ 29 30 struct vmbus_mon_trig { 31 uint32_t pending; 32 uint32_t armed; 33 } __rte_packed; 34 35 #define VMBUS_MONTRIGS_MAX 4 36 #define VMBUS_MONTRIG_LEN 32 37 38 /* 39 * Hyper-V Monitor Notification Facility 40 */ 41 struct hyperv_mon_param { 42 uint32_t connid; 43 uint16_t evtflag_ofs; 44 uint16_t rsvd; 45 } __rte_packed; 46 47 struct vmbus_mon_page { 48 uint32_t state; 49 uint32_t rsvd1; 50 51 struct vmbus_mon_trig trigs[VMBUS_MONTRIGS_MAX]; 52 uint8_t rsvd2[536]; 53 54 uint16_t lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 55 uint8_t rsvd3[256]; 56 57 struct hyperv_mon_param 58 param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 59 uint8_t rsvd4[1984]; 60 } __rte_packed; 61 62 /* 63 * Buffer ring 64 */ 65 66 struct vmbus_bufring { 67 volatile uint32_t windex; 68 volatile uint32_t rindex; 69 70 /* 71 * Interrupt mask {0,1} 72 * 73 * For TX bufring, host set this to 1, when it is processing 74 * the TX bufring, so that we can safely skip the TX event 75 * notification to host. 76 * 77 * For RX bufring, once this is set to 1 by us, host will not 78 * further dispatch interrupts to us, even if there are data 79 * pending on the RX bufring. This effectively disables the 80 * interrupt of the channel to which this RX bufring is attached. 81 */ 82 volatile uint32_t imask; 83 84 /* 85 * Win8 uses some of the reserved bits to implement 86 * interrupt driven flow management. On the send side 87 * we can request that the receiver interrupt the sender 88 * when the ring transitions from being full to being able 89 * to handle a message of size "pending_send_sz". 90 * 91 * Add necessary state for this enhancement. 92 */ 93 volatile uint32_t pending_send; 94 uint32_t reserved1[12]; 95 96 union { 97 struct { 98 uint32_t feat_pending_send_sz:1; 99 }; 100 uint32_t value; 101 } feature_bits; 102 103 /* Pad it to rte_mem_page_size() so that data starts on page boundary */ 104 uint8_t reserved2[4028]; 105 106 /* 107 * Ring data starts here + RingDataStartOffset 108 * !!! DO NOT place any fields below this !!! 109 */ 110 uint8_t data[]; 111 } __rte_packed; 112 113 /* 114 * Channel packets 115 */ 116 117 /* Channel packet flags */ 118 #define VMBUS_CHANPKT_TYPE_INBAND 0x0006 119 #define VMBUS_CHANPKT_TYPE_RXBUF 0x0007 120 #define VMBUS_CHANPKT_TYPE_GPA 0x0009 121 #define VMBUS_CHANPKT_TYPE_COMP 0x000b 122 123 #define VMBUS_CHANPKT_FLAG_NONE 0 124 #define VMBUS_CHANPKT_FLAG_RC 0x0001 /* report completion */ 125 126 #define VMBUS_CHANPKT_SIZE_SHIFT 3 127 #define VMBUS_CHANPKT_SIZE_ALIGN (1 << VMBUS_CHANPKT_SIZE_SHIFT) 128 #define VMBUS_CHANPKT_HLEN_MIN \ 129 (sizeof(struct vmbus_chanpkt_hdr) >> VMBUS_CHANPKT_SIZE_SHIFT) 130 131 static inline uint32_t 132 vmbus_chanpkt_getlen(uint16_t pktlen) 133 { 134 return (uint32_t)pktlen << VMBUS_CHANPKT_SIZE_SHIFT; 135 } 136 137 /* 138 * GPA stuffs. 139 */ 140 struct vmbus_gpa_range { 141 uint32_t len; 142 uint32_t ofs; 143 uint64_t page[]; 144 } __rte_packed; 145 146 /* This is actually vmbus_gpa_range.gpa_page[1] */ 147 struct vmbus_gpa { 148 uint32_t len; 149 uint32_t ofs; 150 uint64_t page; 151 } __rte_packed; 152 153 struct vmbus_chanpkt_hdr { 154 uint16_t type; /* VMBUS_CHANPKT_TYPE_ */ 155 uint16_t hlen; /* header len, in 8 bytes */ 156 uint16_t tlen; /* total len, in 8 bytes */ 157 uint16_t flags; /* VMBUS_CHANPKT_FLAG_ */ 158 uint64_t xactid; 159 } __rte_packed; 160 161 static inline uint32_t 162 vmbus_chanpkt_datalen(const struct vmbus_chanpkt_hdr *pkt) 163 { 164 return vmbus_chanpkt_getlen(pkt->tlen) 165 - vmbus_chanpkt_getlen(pkt->hlen); 166 } 167 168 struct vmbus_chanpkt { 169 struct vmbus_chanpkt_hdr hdr; 170 } __rte_packed; 171 172 struct vmbus_rxbuf_desc { 173 uint32_t len; 174 uint32_t ofs; 175 } __rte_packed; 176 177 struct vmbus_chanpkt_rxbuf { 178 struct vmbus_chanpkt_hdr hdr; 179 uint16_t rxbuf_id; 180 uint16_t rsvd; 181 uint32_t rxbuf_cnt; 182 struct vmbus_rxbuf_desc rxbuf[]; 183 } __rte_packed; 184 185 struct vmbus_chanpkt_sglist { 186 struct vmbus_chanpkt_hdr hdr; 187 uint32_t rsvd; 188 uint32_t gpa_cnt; 189 struct vmbus_gpa gpa[]; 190 } __rte_packed; 191 192 /* 193 * Channel messages 194 * - Embedded in vmbus_message.msg_data, e.g. response and notification. 195 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request. 196 */ 197 198 #define VMBUS_CHANMSG_TYPE_CHOFFER 1 /* NOTE */ 199 #define VMBUS_CHANMSG_TYPE_CHRESCIND 2 /* NOTE */ 200 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */ 201 #define VMBUS_CHANMSG_TYPE_CHOFFER_DONE 4 /* NOTE */ 202 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */ 203 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */ 204 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */ 205 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */ 206 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */ 207 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */ 208 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */ 209 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */ 210 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */ 211 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */ 212 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */ 213 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */ 214 #define VMBUS_CHANMSG_TYPE_MAX 22 215 216 struct vmbus_chanmsg_hdr { 217 uint32_t type; /* VMBUS_CHANMSG_TYPE_ */ 218 uint32_t rsvd; 219 } __rte_packed; 220 221 /* VMBUS_CHANMSG_TYPE_CONNECT */ 222 struct vmbus_chanmsg_connect { 223 struct vmbus_chanmsg_hdr hdr; 224 uint32_t ver; 225 uint32_t rsvd; 226 uint64_t evtflags; 227 uint64_t mnf1; 228 uint64_t mnf2; 229 } __rte_packed; 230 231 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */ 232 struct vmbus_chanmsg_connect_resp { 233 struct vmbus_chanmsg_hdr hdr; 234 uint8_t done; 235 } __rte_packed; 236 237 /* VMBUS_CHANMSG_TYPE_CHREQUEST */ 238 struct vmbus_chanmsg_chrequest { 239 struct vmbus_chanmsg_hdr hdr; 240 } __rte_packed; 241 242 /* VMBUS_CHANMSG_TYPE_DISCONNECT */ 243 struct vmbus_chanmsg_disconnect { 244 struct vmbus_chanmsg_hdr hdr; 245 } __rte_packed; 246 247 /* VMBUS_CHANMSG_TYPE_CHOPEN */ 248 struct vmbus_chanmsg_chopen { 249 struct vmbus_chanmsg_hdr hdr; 250 uint32_t chanid; 251 uint32_t openid; 252 uint32_t gpadl; 253 uint32_t vcpuid; 254 uint32_t txbr_pgcnt; 255 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120 256 uint8_t udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE]; 257 } __rte_packed; 258 259 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */ 260 struct vmbus_chanmsg_chopen_resp { 261 struct vmbus_chanmsg_hdr hdr; 262 uint32_t chanid; 263 uint32_t openid; 264 uint32_t status; 265 } __rte_packed; 266 267 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */ 268 struct vmbus_chanmsg_gpadl_conn { 269 struct vmbus_chanmsg_hdr hdr; 270 uint32_t chanid; 271 uint32_t gpadl; 272 uint16_t range_len; 273 uint16_t range_cnt; 274 struct vmbus_gpa_range range; 275 } __rte_packed; 276 277 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26 278 279 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */ 280 struct vmbus_chanmsg_gpadl_subconn { 281 struct vmbus_chanmsg_hdr hdr; 282 uint32_t msgno; 283 uint32_t gpadl; 284 uint64_t gpa_page[]; 285 } __rte_packed; 286 287 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28 288 289 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */ 290 struct vmbus_chanmsg_gpadl_connresp { 291 struct vmbus_chanmsg_hdr hdr; 292 uint32_t chanid; 293 uint32_t gpadl; 294 uint32_t status; 295 } __rte_packed; 296 297 /* VMBUS_CHANMSG_TYPE_CHCLOSE */ 298 struct vmbus_chanmsg_chclose { 299 struct vmbus_chanmsg_hdr hdr; 300 uint32_t chanid; 301 } __rte_packed; 302 303 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */ 304 struct vmbus_chanmsg_gpadl_disconn { 305 struct vmbus_chanmsg_hdr hdr; 306 uint32_t chanid; 307 uint32_t gpadl; 308 } __rte_packed; 309 310 /* VMBUS_CHANMSG_TYPE_CHFREE */ 311 struct vmbus_chanmsg_chfree { 312 struct vmbus_chanmsg_hdr hdr; 313 uint32_t chanid; 314 } __rte_packed; 315 316 /* VMBUS_CHANMSG_TYPE_CHRESCIND */ 317 struct vmbus_chanmsg_chrescind { 318 struct vmbus_chanmsg_hdr hdr; 319 uint32_t chanid; 320 } __rte_packed; 321 322 /* VMBUS_CHANMSG_TYPE_CHOFFER */ 323 struct vmbus_chanmsg_choffer { 324 struct vmbus_chanmsg_hdr hdr; 325 rte_uuid_t chtype; 326 rte_uuid_t chinst; 327 uint64_t chlat; /* unit: 100ns */ 328 uint32_t chrev; 329 uint32_t svrctx_sz; 330 uint16_t chflags; 331 uint16_t mmio_sz; /* unit: MB */ 332 uint8_t udata[120]; 333 uint16_t subidx; 334 uint16_t rsvd; 335 uint32_t chanid; 336 uint8_t montrig; 337 uint8_t flags1; /* VMBUS_CHOFFER_FLAG1_ */ 338 uint16_t flags2; 339 uint32_t connid; 340 } __rte_packed; 341 342 #define VMBUS_CHOFFER_FLAG1_HASMNF 0x01 343 344 #endif /* !_VMBUS_REG_H_ */ 345