blob: b7b0721942821b1f24e0fc54f371370cff043bbe [file] [log] [blame]
Thomas Gleixner685a6bf2019-05-29 16:57:36 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Andy Kingd021c342013-02-06 14:23:56 +00002/*
3 * VMware vSockets Driver
4 *
5 * Copyright (C) 2013 VMware, Inc. All rights reserved.
Andy Kingd021c342013-02-06 14:23:56 +00006 */
7
8#ifndef _VMCI_TRANSPORT_H_
9#define _VMCI_TRANSPORT_H_
10
11#include <linux/vmw_vmci_defs.h>
12#include <linux/vmw_vmci_api.h>
13
Asias He82a54d02013-07-25 17:39:34 +080014#include <net/vsock_addr.h>
15#include <net/af_vsock.h>
Andy Kingd021c342013-02-06 14:23:56 +000016
17/* If the packet format changes in a release then this should change too. */
18#define VMCI_TRANSPORT_PACKET_VERSION 1
19
20/* The resource ID on which control packets are sent. */
21#define VMCI_TRANSPORT_PACKET_RID 1
22
Reilly Grant2a89f922013-03-14 11:55:41 +000023/* The resource ID on which control packets are sent to the hypervisor. */
24#define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15
25
Andy Kingd021c342013-02-06 14:23:56 +000026#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)
29
30#define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans))
31
32enum 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
47};
48
49struct vmci_transport_waiting_info {
50 u64 generation;
51 u64 offset;
52};
53
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
58 * format.
59 */
60struct vmci_transport_packet {
61 struct vmci_datagram dg;
62 u8 version;
63 u8 type;
64 u16 proto;
65 u32 src_port;
66 u32 dst_port;
67 u32 _reserved2;
68 union {
69 u64 size;
70 u64 mode;
71 struct vmci_handle handle;
72 struct vmci_transport_waiting_info wait;
73 } u;
74};
75
76struct 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;
88};
89
90struct 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;
95};
96
97union vmci_transport_notify {
98 struct vmci_transport_notify_pkt pkt;
99 struct vmci_transport_notify_pkt_q_state pkt_q_state;
100};
101
102/* Our transport-specific data. */
103struct vmci_transport {
104 /* For DGRAMs. */
105 struct vmci_handle dg_handle;
106 /* For STREAMs. */
107 struct vmci_handle qp_handle;
108 struct vmci_qp *qpair;
109 u64 produce_size;
110 u64 consume_size;
Andy Kingd021c342013-02-06 14:23:56 +0000111 u32 detach_sub_id;
112 union vmci_transport_notify notify;
Julia Lawall3b22dae2015-11-21 18:39:17 +0100113 const struct vmci_transport_notify_ops *notify_ops;
Jorgen Hansen4ef7ea92015-10-21 04:53:56 -0700114 struct list_head elem;
115 struct sock *sk;
116 spinlock_t lock; /* protects sk. */
Andy Kingd021c342013-02-06 14:23:56 +0000117};
118
119int vmci_transport_register(void);
120void vmci_transport_unregister(void);
121
122int vmci_transport_send_wrote_bh(struct sockaddr_vm *dst,
123 struct sockaddr_vm *src);
124int vmci_transport_send_read_bh(struct sockaddr_vm *dst,
125 struct sockaddr_vm *src);
126int vmci_transport_send_wrote(struct sock *sk);
127int vmci_transport_send_read(struct sock *sk);
128int vmci_transport_send_waiting_write(struct sock *sk,
129 struct vmci_transport_waiting_info *wait);
130int vmci_transport_send_waiting_read(struct sock *sk,
131 struct vmci_transport_waiting_info *wait);
132
133#endif