163a93856SMark Peek /*- 263a93856SMark Peek * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 363a93856SMark Peek * 4*8c302b2eSMark Peek * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0) 563a93856SMark Peek * 663a93856SMark Peek * $FreeBSD$ 763a93856SMark Peek */ 863a93856SMark Peek 963a93856SMark Peek #ifndef _VMCI_CALL_DEFS_H_ 1063a93856SMark Peek #define _VMCI_CALL_DEFS_H_ 1163a93856SMark Peek 1263a93856SMark Peek #include "vmci_defs.h" 1363a93856SMark Peek 1463a93856SMark Peek /* 1563a93856SMark Peek * All structs here are an integral size of their largest member, ie. a struct 1663a93856SMark Peek * with at least one 8-byte member will have a size that is an integral of 8. 1763a93856SMark Peek * A struct which has a largest member of size 4 will have a size that is an 1863a93856SMark Peek * integral of 4. 1963a93856SMark Peek */ 2063a93856SMark Peek 2163a93856SMark Peek /* 2263a93856SMark Peek * Base struct for vmci datagrams. 2363a93856SMark Peek */ 2463a93856SMark Peek struct vmci_datagram { 2563a93856SMark Peek struct vmci_handle dst; 2663a93856SMark Peek struct vmci_handle src; 2763a93856SMark Peek uint64_t payload_size; 2863a93856SMark Peek }; 2963a93856SMark Peek 3063a93856SMark Peek /* 3163a93856SMark Peek * Second flag is for creating a well-known handle instead of a per context 3263a93856SMark Peek * handle. Next flag is for deferring datagram delivery, so that the 3363a93856SMark Peek * datagram callback is invoked in a delayed context (not interrupt context). 3463a93856SMark Peek */ 3563a93856SMark Peek #define VMCI_FLAG_DG_NONE 0 3663a93856SMark Peek #define VMCI_FLAG_WELLKNOWN_DG_HND 0x1 3763a93856SMark Peek #define VMCI_FLAG_ANYCID_DG_HND 0x2 3863a93856SMark Peek #define VMCI_FLAG_DG_DELAYED_CB 0x4 3963a93856SMark Peek 4063a93856SMark Peek /* Event callback should fire in a delayed context (not interrupt context.) */ 4163a93856SMark Peek #define VMCI_FLAG_EVENT_NONE 0 4263a93856SMark Peek #define VMCI_FLAG_EVENT_DELAYED_CB 0x1 4363a93856SMark Peek 4463a93856SMark Peek /* 4563a93856SMark Peek * Maximum supported size of a VMCI datagram for routable datagrams. 4663a93856SMark Peek * Datagrams going to the hypervisor are allowed to be larger. 4763a93856SMark Peek */ 4863a93856SMark Peek #define VMCI_MAX_DG_SIZE \ 4963a93856SMark Peek (17 * 4096) 5063a93856SMark Peek #define VMCI_MAX_DG_PAYLOAD_SIZE \ 5163a93856SMark Peek (VMCI_MAX_DG_SIZE - sizeof(struct vmci_datagram)) 5263a93856SMark Peek #define VMCI_DG_PAYLOAD(_dg) \ 5363a93856SMark Peek (void *)((char *)(_dg) + sizeof(struct vmci_datagram)) 5463a93856SMark Peek #define VMCI_DG_HEADERSIZE \ 5563a93856SMark Peek sizeof(struct vmci_datagram) 5663a93856SMark Peek #define VMCI_DG_SIZE(_dg) \ 5763a93856SMark Peek (VMCI_DG_HEADERSIZE + (size_t)(_dg)->payload_size) 5863a93856SMark Peek #define VMCI_DG_SIZE_ALIGNED(_dg) \ 5963a93856SMark Peek ((VMCI_DG_SIZE(_dg) + 7) & (size_t)~7) 6063a93856SMark Peek 6163a93856SMark Peek /* 6263a93856SMark Peek * Struct used for querying, via VMCI_RESOURCES_QUERY, the availability of 6363a93856SMark Peek * hypervisor resources. 6463a93856SMark Peek * Struct size is 16 bytes. All fields in struct are aligned to their natural 6563a93856SMark Peek * alignment. 6663a93856SMark Peek */ 6763a93856SMark Peek struct vmci_resources_query_hdr { 6863a93856SMark Peek struct vmci_datagram hdr; 6963a93856SMark Peek uint32_t num_resources; 7063a93856SMark Peek uint32_t _padding; 7163a93856SMark Peek }; 7263a93856SMark Peek 7363a93856SMark Peek /* 7463a93856SMark Peek * Convenience struct for negotiating vectors. Must match layout of 7563a93856SMark Peek * vmci_resource_query_hdr minus the struct vmci_datagram header. 7663a93856SMark Peek */ 7763a93856SMark Peek struct vmci_resources_query_msg { 7863a93856SMark Peek uint32_t num_resources; 7963a93856SMark Peek uint32_t _padding; 8063a93856SMark Peek vmci_resource resources[1]; 8163a93856SMark Peek }; 8263a93856SMark Peek 8363a93856SMark Peek /* 8463a93856SMark Peek * Struct used for setting the notification bitmap. All fields in struct are 8563a93856SMark Peek * aligned to their natural alignment. 8663a93856SMark Peek */ 8763a93856SMark Peek struct vmci_notify_bitmap_set_msg { 8863a93856SMark Peek struct vmci_datagram hdr; 8963a93856SMark Peek PPN bitmap_ppn; 9063a93856SMark Peek uint32_t _pad; 9163a93856SMark Peek }; 9263a93856SMark Peek 9363a93856SMark Peek /* 9463a93856SMark Peek * Struct used for linking a doorbell handle with an index in the notify 9563a93856SMark Peek * bitmap. All fields in struct are aligned to their natural alignment. 9663a93856SMark Peek */ 9763a93856SMark Peek struct vmci_doorbell_link_msg { 9863a93856SMark Peek struct vmci_datagram hdr; 9963a93856SMark Peek struct vmci_handle handle; 10063a93856SMark Peek uint64_t notify_idx; 10163a93856SMark Peek }; 10263a93856SMark Peek 10363a93856SMark Peek /* 10463a93856SMark Peek * Struct used for unlinking a doorbell handle from an index in the notify 10563a93856SMark Peek * bitmap. All fields in struct are aligned to their natural alignment. 10663a93856SMark Peek */ 10763a93856SMark Peek struct vmci_doorbell_unlink_msg { 10863a93856SMark Peek struct vmci_datagram hdr; 10963a93856SMark Peek struct vmci_handle handle; 11063a93856SMark Peek }; 11163a93856SMark Peek 11263a93856SMark Peek /* 11363a93856SMark Peek * Struct used for generating a notification on a doorbell handle. All fields 11463a93856SMark Peek * in struct are aligned to their natural alignment. 11563a93856SMark Peek */ 11663a93856SMark Peek struct vmci_doorbell_notify_msg { 11763a93856SMark Peek struct vmci_datagram hdr; 11863a93856SMark Peek struct vmci_handle handle; 11963a93856SMark Peek }; 12063a93856SMark Peek 12163a93856SMark Peek /* 12263a93856SMark Peek * This struct is used to contain data for events. Size of this struct is a 12363a93856SMark Peek * multiple of 8 bytes, and all fields are aligned to their natural alignment. 12463a93856SMark Peek */ 12563a93856SMark Peek struct vmci_event_data { 12663a93856SMark Peek vmci_event_type event; /* 4 bytes. */ 12763a93856SMark Peek uint32_t _pad; 12863a93856SMark Peek /* 12963a93856SMark Peek * Event payload is put here. 13063a93856SMark Peek */ 13163a93856SMark Peek }; 13263a93856SMark Peek 13363a93856SMark Peek /* Callback needed for correctly waiting on events. */ 13463a93856SMark Peek 13563a93856SMark Peek typedef int 13663a93856SMark Peek (*vmci_datagram_recv_cb)(void *client_data, struct vmci_datagram *msg); 13763a93856SMark Peek 13863a93856SMark Peek /* 13963a93856SMark Peek * We use the following inline function to access the payload data associated 14063a93856SMark Peek * with an event data. 14163a93856SMark Peek */ 14263a93856SMark Peek 14363a93856SMark Peek static inline void * 14463a93856SMark Peek vmci_event_data_payload(struct vmci_event_data *ev_data) 14563a93856SMark Peek { 14663a93856SMark Peek 14763a93856SMark Peek return ((void *)((char *)ev_data + sizeof(*ev_data))); 14863a93856SMark Peek } 14963a93856SMark Peek 15063a93856SMark Peek /* 15163a93856SMark Peek * Define the different VMCI_EVENT payload data types here. All structs must 15263a93856SMark Peek * be a multiple of 8 bytes, and fields must be aligned to their natural 15363a93856SMark Peek * alignment. 15463a93856SMark Peek */ 15563a93856SMark Peek struct vmci_event_payload_context { 15663a93856SMark Peek vmci_id context_id; /* 4 bytes. */ 15763a93856SMark Peek uint32_t _pad; 15863a93856SMark Peek }; 15963a93856SMark Peek 16063a93856SMark Peek struct vmci_event_payload_qp { 16163a93856SMark Peek /* QueuePair handle. */ 16263a93856SMark Peek struct vmci_handle handle; 16363a93856SMark Peek /* Context id of attaching/detaching VM. */ 16463a93856SMark Peek vmci_id peer_id; 16563a93856SMark Peek uint32_t _pad; 16663a93856SMark Peek }; 16763a93856SMark Peek 16863a93856SMark Peek /* 16963a93856SMark Peek * We define the following struct to get the size of the maximum event data 17063a93856SMark Peek * the hypervisor may send to the guest. If adding a new event payload type 17163a93856SMark Peek * above, add it to the following struct too (inside the union). 17263a93856SMark Peek */ 17363a93856SMark Peek struct vmci_event_data_max { 17463a93856SMark Peek struct vmci_event_data event_data; 17563a93856SMark Peek union { 17663a93856SMark Peek struct vmci_event_payload_context context_payload; 17763a93856SMark Peek struct vmci_event_payload_qp qp_payload; 17863a93856SMark Peek } ev_data_payload; 17963a93856SMark Peek }; 18063a93856SMark Peek 18163a93856SMark Peek /* 18263a93856SMark Peek * Struct used for VMCI_EVENT_SUBSCRIBE/UNSUBSCRIBE and VMCI_EVENT_HANDLER 18363a93856SMark Peek * messages. Struct size is 32 bytes. All fields in struct are aligned to 18463a93856SMark Peek * their natural alignment. 18563a93856SMark Peek */ 18663a93856SMark Peek struct vmci_event_msg { 18763a93856SMark Peek struct vmci_datagram hdr; 18863a93856SMark Peek struct vmci_event_data event_data; /* Has event type & payload. */ 18963a93856SMark Peek /* 19063a93856SMark Peek * Payload gets put here. 19163a93856SMark Peek */ 19263a93856SMark Peek }; 19363a93856SMark Peek 19463a93856SMark Peek /* 19563a93856SMark Peek * We use the following inline function to access the payload data associated 19663a93856SMark Peek * with an event message. 19763a93856SMark Peek */ 19863a93856SMark Peek 19963a93856SMark Peek static inline void * 20063a93856SMark Peek vmci_event_msg_payload(struct vmci_event_msg *e_msg) 20163a93856SMark Peek { 20263a93856SMark Peek 20363a93856SMark Peek return (vmci_event_data_payload(&e_msg->event_data)); 20463a93856SMark Peek } 20563a93856SMark Peek 20663a93856SMark Peek /* Flags for VMCI QueuePair API. */ 20763a93856SMark Peek #define VMCI_QPFLAG_ATTACH_ONLY \ 20863a93856SMark Peek 0x1 /* Fail alloc if QP not created by peer. */ 20963a93856SMark Peek #define VMCI_QPFLAG_LOCAL \ 21063a93856SMark Peek 0x2 /* Only allow attaches from local context. */ 21163a93856SMark Peek #define VMCI_QPFLAG_NONBLOCK \ 21263a93856SMark Peek 0x4 /* Host won't block when guest is quiesced. */ 21363a93856SMark Peek 21463a93856SMark Peek /* For asymmetric queuepairs, update as new flags are added. */ 21563a93856SMark Peek #define VMCI_QP_ASYMM \ 21663a93856SMark Peek VMCI_QPFLAG_NONBLOCK 21763a93856SMark Peek #define VMCI_QP_ASYMM_PEER \ 21863a93856SMark Peek (VMCI_QPFLAG_ATTACH_ONLY | VMCI_QP_ASYMM) 21963a93856SMark Peek 22063a93856SMark Peek /* Update the following (bitwise OR flags) while adding new flags. */ 22163a93856SMark Peek #define VMCI_QP_ALL_FLAGS \ 22263a93856SMark Peek (VMCI_QPFLAG_ATTACH_ONLY | VMCI_QPFLAG_LOCAL | VMCI_QPFLAG_NONBLOCK) 22363a93856SMark Peek 22463a93856SMark Peek /* 22563a93856SMark Peek * Structs used for QueuePair alloc and detach messages. We align fields of 22663a93856SMark Peek * these structs to 64 bit boundaries. 22763a93856SMark Peek */ 22863a93856SMark Peek struct vmci_queue_pair_alloc_msg { 22963a93856SMark Peek struct vmci_datagram hdr; 23063a93856SMark Peek struct vmci_handle handle; 23163a93856SMark Peek vmci_id peer; /* 32bit field. */ 23263a93856SMark Peek uint32_t flags; 23363a93856SMark Peek uint64_t produce_size; 23463a93856SMark Peek uint64_t consume_size; 23563a93856SMark Peek uint64_t num_ppns; 23663a93856SMark Peek /* List of PPNs placed here. */ 23763a93856SMark Peek }; 23863a93856SMark Peek 23963a93856SMark Peek struct vmci_queue_pair_detach_msg { 24063a93856SMark Peek struct vmci_datagram hdr; 24163a93856SMark Peek struct vmci_handle handle; 24263a93856SMark Peek }; 24363a93856SMark Peek 24463a93856SMark Peek #endif /* !_VMCI_CALL_DEFS_H_ */ 245