1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * VMware vSockets Driver
5 * Copyright (C) 2013 VMware, Inc. All rights reserved.
8 #ifndef _VMCI_TRANSPORT_H_
9 #define _VMCI_TRANSPORT_H_
11 #include <linux/vmw_vmci_defs.h>
12 #include <linux/vmw_vmci_api.h>
14 #include <net/vsock_addr.h>
15 #include <net/af_vsock.h>
17 /* If the packet format changes in a release then this should change too. */
18 #define VMCI_TRANSPORT_PACKET_VERSION 1
20 /* The resource ID on which control packets are sent. */
21 #define VMCI_TRANSPORT_PACKET_RID 1
23 /* The resource ID on which control packets are sent to the hypervisor. */
24 #define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15
26 #define VSOCK_PROTO_INVALID 0
27 #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0)
28 #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY)
30 #define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans))
32 enum vmci_transport_packet_type {
33 VMCI_TRANSPORT_PACKET_TYPE_INVALID = 0,
34 VMCI_TRANSPORT_PACKET_TYPE_REQUEST,
35 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE,
36 VMCI_TRANSPORT_PACKET_TYPE_OFFER,
37 VMCI_TRANSPORT_PACKET_TYPE_ATTACH,
38 VMCI_TRANSPORT_PACKET_TYPE_WROTE,
39 VMCI_TRANSPORT_PACKET_TYPE_READ,
40 VMCI_TRANSPORT_PACKET_TYPE_RST,
41 VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN,
42 VMCI_TRANSPORT_PACKET_TYPE_WAITING_WRITE,
43 VMCI_TRANSPORT_PACKET_TYPE_WAITING_READ,
44 VMCI_TRANSPORT_PACKET_TYPE_REQUEST2,
45 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE2,
46 VMCI_TRANSPORT_PACKET_TYPE_MAX
49 struct vmci_transport_waiting_info {
54 /* Control packet type for STREAM sockets. DGRAMs have no control packets nor
55 * special packet header for data packets, they are just raw VMCI DGRAM
56 * messages. For STREAMs, control packets are sent over the control channel
57 * while data is written and read directly from queue pairs with no packet
60 struct vmci_transport_packet {
61 struct vmci_datagram dg;
71 struct vmci_handle handle;
72 struct vmci_transport_waiting_info wait;
76 struct vmci_transport_notify_pkt {
77 u64 write_notify_window;
78 u64 write_notify_min_window;
79 bool peer_waiting_read;
80 bool peer_waiting_write;
81 bool peer_waiting_write_detected;
82 bool sent_waiting_read;
83 bool sent_waiting_write;
84 struct vmci_transport_waiting_info peer_waiting_read_info;
85 struct vmci_transport_waiting_info peer_waiting_write_info;
86 u64 produce_q_generation;
87 u64 consume_q_generation;
90 struct vmci_transport_notify_pkt_q_state {
91 u64 write_notify_window;
92 u64 write_notify_min_window;
93 bool peer_waiting_write;
94 bool peer_waiting_write_detected;
97 union vmci_transport_notify {
98 struct vmci_transport_notify_pkt pkt;
99 struct vmci_transport_notify_pkt_q_state pkt_q_state;
102 /* Our transport-specific data. */
103 struct vmci_transport {
105 struct vmci_handle dg_handle;
107 struct vmci_handle qp_handle;
108 struct vmci_qp *qpair;
112 union vmci_transport_notify notify;
113 const struct vmci_transport_notify_ops *notify_ops;
114 struct list_head elem;
116 spinlock_t lock; /* protects sk. */
119 int vmci_transport_register(void);
120 void vmci_transport_unregister(void);
122 int vmci_transport_send_wrote_bh(struct sockaddr_vm *dst,
123 struct sockaddr_vm *src);
124 int vmci_transport_send_read_bh(struct sockaddr_vm *dst,
125 struct sockaddr_vm *src);
126 int vmci_transport_send_wrote(struct sock *sk);
127 int vmci_transport_send_read(struct sock *sk);
128 int vmci_transport_send_waiting_write(struct sock *sk,
129 struct vmci_transport_waiting_info *wait);
130 int vmci_transport_send_waiting_read(struct sock *sk,
131 struct vmci_transport_waiting_info *wait);