]> git.ipfire.org Git - thirdparty/linux.git/blame - include/linux/virtio_vsock.h
Merge tag 'io_uring-5.7-2020-05-22' of git://git.kernel.dk/linux-block
[thirdparty/linux.git] / include / linux / virtio_vsock.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
06a8fc78
AH
2#ifndef _LINUX_VIRTIO_VSOCK_H
3#define _LINUX_VIRTIO_VSOCK_H
4
5#include <uapi/linux/virtio_vsock.h>
6#include <linux/socket.h>
7#include <net/sock.h>
8#include <net/af_vsock.h>
9
06a8fc78
AH
10#define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4)
11#define VIRTIO_VSOCK_MAX_BUF_SIZE 0xFFFFFFFFUL
12#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
13
14enum {
15 VSOCK_VQ_RX = 0, /* for host to guest data */
16 VSOCK_VQ_TX = 1, /* for guest to host data */
17 VSOCK_VQ_EVENT = 2,
18 VSOCK_VQ_MAX = 3,
19};
20
21/* Per-socket state (accessed via vsk->trans) */
22struct virtio_vsock_sock {
23 struct vsock_sock *vsk;
24
06a8fc78
AH
25 spinlock_t tx_lock;
26 spinlock_t rx_lock;
27
28 /* Protected by tx_lock */
29 u32 tx_cnt;
06a8fc78
AH
30 u32 peer_fwd_cnt;
31 u32 peer_buf_alloc;
32
33 /* Protected by rx_lock */
34 u32 fwd_cnt;
b89d882d 35 u32 last_fwd_cnt;
06a8fc78 36 u32 rx_bytes;
9632e9f6 37 u32 buf_alloc;
06a8fc78
AH
38 struct list_head rx_queue;
39};
40
41struct virtio_vsock_pkt {
42 struct virtio_vsock_hdr hdr;
06a8fc78 43 struct list_head list;
36d277ba
PT
44 /* socket refcnt not held, only use for cancellation */
45 struct vsock_sock *vsk;
06a8fc78 46 void *buf;
473c7391 47 u32 buf_len;
06a8fc78
AH
48 u32 len;
49 u32 off;
50 bool reply;
a78d1639 51 bool tap_delivered;
06a8fc78
AH
52};
53
54struct virtio_vsock_pkt_info {
55 u32 remote_cid, remote_port;
36d277ba 56 struct vsock_sock *vsk;
06a8fc78
AH
57 struct msghdr *msg;
58 u32 pkt_len;
59 u16 type;
60 u16 op;
61 u32 flags;
62 bool reply;
63};
64
65struct virtio_transport {
66 /* This must be the first field */
67 struct vsock_transport transport;
68
69 /* Takes ownership of the packet */
70 int (*send_pkt)(struct virtio_vsock_pkt *pkt);
71};
72
73ssize_t
74virtio_transport_stream_dequeue(struct vsock_sock *vsk,
75 struct msghdr *msg,
76 size_t len,
77 int type);
78int
79virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
80 struct msghdr *msg,
81 size_t len, int flags);
82
83s64 virtio_transport_stream_has_data(struct vsock_sock *vsk);
84s64 virtio_transport_stream_has_space(struct vsock_sock *vsk);
85
86int virtio_transport_do_socket_init(struct vsock_sock *vsk,
87 struct vsock_sock *psk);
06a8fc78
AH
88int
89virtio_transport_notify_poll_in(struct vsock_sock *vsk,
90 size_t target,
91 bool *data_ready_now);
92int
93virtio_transport_notify_poll_out(struct vsock_sock *vsk,
94 size_t target,
95 bool *space_available_now);
96
97int virtio_transport_notify_recv_init(struct vsock_sock *vsk,
98 size_t target, struct vsock_transport_recv_notify_data *data);
99int virtio_transport_notify_recv_pre_block(struct vsock_sock *vsk,
100 size_t target, struct vsock_transport_recv_notify_data *data);
101int virtio_transport_notify_recv_pre_dequeue(struct vsock_sock *vsk,
102 size_t target, struct vsock_transport_recv_notify_data *data);
103int virtio_transport_notify_recv_post_dequeue(struct vsock_sock *vsk,
104 size_t target, ssize_t copied, bool data_read,
105 struct vsock_transport_recv_notify_data *data);
106int virtio_transport_notify_send_init(struct vsock_sock *vsk,
107 struct vsock_transport_send_notify_data *data);
108int virtio_transport_notify_send_pre_block(struct vsock_sock *vsk,
109 struct vsock_transport_send_notify_data *data);
110int virtio_transport_notify_send_pre_enqueue(struct vsock_sock *vsk,
111 struct vsock_transport_send_notify_data *data);
112int virtio_transport_notify_send_post_enqueue(struct vsock_sock *vsk,
113 ssize_t written, struct vsock_transport_send_notify_data *data);
b9f2b0ff 114void virtio_transport_notify_buffer_size(struct vsock_sock *vsk, u64 *val);
06a8fc78
AH
115
116u64 virtio_transport_stream_rcvhiwat(struct vsock_sock *vsk);
117bool virtio_transport_stream_is_active(struct vsock_sock *vsk);
118bool virtio_transport_stream_allow(u32 cid, u32 port);
119int virtio_transport_dgram_bind(struct vsock_sock *vsk,
120 struct sockaddr_vm *addr);
121bool virtio_transport_dgram_allow(u32 cid, u32 port);
122
123int virtio_transport_connect(struct vsock_sock *vsk);
124
125int virtio_transport_shutdown(struct vsock_sock *vsk, int mode);
126
127void virtio_transport_release(struct vsock_sock *vsk);
128
129ssize_t
130virtio_transport_stream_enqueue(struct vsock_sock *vsk,
131 struct msghdr *msg,
132 size_t len);
133int
134virtio_transport_dgram_enqueue(struct vsock_sock *vsk,
135 struct sockaddr_vm *remote_addr,
136 struct msghdr *msg,
137 size_t len);
138
139void virtio_transport_destruct(struct vsock_sock *vsk);
140
4c7246dc
SG
141void virtio_transport_recv_pkt(struct virtio_transport *t,
142 struct virtio_vsock_pkt *pkt);
06a8fc78
AH
143void virtio_transport_free_pkt(struct virtio_vsock_pkt *pkt);
144void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsock_pkt *pkt);
145u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted);
146void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit);
82dfb540 147void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt *pkt);
06a8fc78
AH
148
149#endif /* _LINUX_VIRTIO_VSOCK_H */