2 * VMware vSockets Driver
4 * Copyright (C) 2013 VMware, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation version 2 and no later version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #ifndef _VMCI_TRANSPORT_H_
17 #define _VMCI_TRANSPORT_H_
19 #include <linux/vmw_vmci_defs.h>
20 #include <linux/vmw_vmci_api.h>
22 #include "vsock_addr.h"
25 /* If the packet format changes in a release then this should change too. */
26 #define VMCI_TRANSPORT_PACKET_VERSION 1
28 /* The resource ID on which control packets are sent. */
29 #define VMCI_TRANSPORT_PACKET_RID 1
31 /* The resource ID on which control packets are sent to the hypervisor. */
32 #define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15
34 #define VSOCK_PROTO_INVALID 0
35 #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0)
36 #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY)
38 #define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans))
40 enum vmci_transport_packet_type
{
41 VMCI_TRANSPORT_PACKET_TYPE_INVALID
= 0,
42 VMCI_TRANSPORT_PACKET_TYPE_REQUEST
,
43 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE
,
44 VMCI_TRANSPORT_PACKET_TYPE_OFFER
,
45 VMCI_TRANSPORT_PACKET_TYPE_ATTACH
,
46 VMCI_TRANSPORT_PACKET_TYPE_WROTE
,
47 VMCI_TRANSPORT_PACKET_TYPE_READ
,
48 VMCI_TRANSPORT_PACKET_TYPE_RST
,
49 VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN
,
50 VMCI_TRANSPORT_PACKET_TYPE_WAITING_WRITE
,
51 VMCI_TRANSPORT_PACKET_TYPE_WAITING_READ
,
52 VMCI_TRANSPORT_PACKET_TYPE_REQUEST2
,
53 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE2
,
54 VMCI_TRANSPORT_PACKET_TYPE_MAX
57 struct vmci_transport_waiting_info
{
62 /* Control packet type for STREAM sockets. DGRAMs have no control packets nor
63 * special packet header for data packets, they are just raw VMCI DGRAM
64 * messages. For STREAMs, control packets are sent over the control channel
65 * while data is written and read directly from queue pairs with no packet
68 struct vmci_transport_packet
{
69 struct vmci_datagram dg
;
79 struct vmci_handle handle
;
80 struct vmci_transport_waiting_info wait
;
84 struct vmci_transport_notify_pkt
{
85 u64 write_notify_window
;
86 u64 write_notify_min_window
;
87 bool peer_waiting_read
;
88 bool peer_waiting_write
;
89 bool peer_waiting_write_detected
;
90 bool sent_waiting_read
;
91 bool sent_waiting_write
;
92 struct vmci_transport_waiting_info peer_waiting_read_info
;
93 struct vmci_transport_waiting_info peer_waiting_write_info
;
94 u64 produce_q_generation
;
95 u64 consume_q_generation
;
98 struct vmci_transport_notify_pkt_q_state
{
99 u64 write_notify_window
;
100 u64 write_notify_min_window
;
101 bool peer_waiting_write
;
102 bool peer_waiting_write_detected
;
105 union vmci_transport_notify
{
106 struct vmci_transport_notify_pkt pkt
;
107 struct vmci_transport_notify_pkt_q_state pkt_q_state
;
110 /* Our transport-specific data. */
111 struct vmci_transport
{
113 struct vmci_handle dg_handle
;
115 struct vmci_handle qp_handle
;
116 struct vmci_qp
*qpair
;
120 u64 queue_pair_min_size
;
121 u64 queue_pair_max_size
;
124 union vmci_transport_notify notify
;
125 struct vmci_transport_notify_ops
*notify_ops
;
128 int vmci_transport_register(void);
129 void vmci_transport_unregister(void);
131 int vmci_transport_send_wrote_bh(struct sockaddr_vm
*dst
,
132 struct sockaddr_vm
*src
);
133 int vmci_transport_send_read_bh(struct sockaddr_vm
*dst
,
134 struct sockaddr_vm
*src
);
135 int vmci_transport_send_wrote(struct sock
*sk
);
136 int vmci_transport_send_read(struct sock
*sk
);
137 int vmci_transport_send_waiting_write(struct sock
*sk
,
138 struct vmci_transport_waiting_info
*wait
);
139 int vmci_transport_send_waiting_read(struct sock
*sk
,
140 struct vmci_transport_waiting_info
*wait
);