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