1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_VIRTIO_VSOCK_H
3 #define _LINUX_VIRTIO_VSOCK_H
5 #include <uapi/linux/virtio_vsock.h>
6 #include <linux/socket.h>
8 #include <net/af_vsock.h>
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)
15 VSOCK_VQ_RX
= 0, /* for host to guest data */
16 VSOCK_VQ_TX
= 1, /* for guest to host data */
21 /* Per-socket state (accessed via vsk->trans) */
22 struct virtio_vsock_sock
{
23 struct vsock_sock
*vsk
;
28 /* Protected by tx_lock */
33 /* Protected by rx_lock */
38 struct list_head rx_queue
;
41 struct virtio_vsock_pkt
{
42 struct virtio_vsock_hdr hdr
;
43 struct list_head list
;
44 /* socket refcnt not held, only use for cancellation */
45 struct vsock_sock
*vsk
;
53 struct virtio_vsock_pkt_info
{
54 u32 remote_cid
, remote_port
;
55 struct vsock_sock
*vsk
;
64 struct virtio_transport
{
65 /* This must be the first field */
66 struct vsock_transport transport
;
68 /* Takes ownership of the packet */
69 int (*send_pkt
)(struct virtio_vsock_pkt
*pkt
);
73 virtio_transport_stream_dequeue(struct vsock_sock
*vsk
,
78 virtio_transport_dgram_dequeue(struct vsock_sock
*vsk
,
80 size_t len
, int flags
);
82 s64
virtio_transport_stream_has_data(struct vsock_sock
*vsk
);
83 s64
virtio_transport_stream_has_space(struct vsock_sock
*vsk
);
85 int virtio_transport_do_socket_init(struct vsock_sock
*vsk
,
86 struct vsock_sock
*psk
);
88 virtio_transport_notify_poll_in(struct vsock_sock
*vsk
,
90 bool *data_ready_now
);
92 virtio_transport_notify_poll_out(struct vsock_sock
*vsk
,
94 bool *space_available_now
);
96 int virtio_transport_notify_recv_init(struct vsock_sock
*vsk
,
97 size_t target
, struct vsock_transport_recv_notify_data
*data
);
98 int virtio_transport_notify_recv_pre_block(struct vsock_sock
*vsk
,
99 size_t target
, struct vsock_transport_recv_notify_data
*data
);
100 int virtio_transport_notify_recv_pre_dequeue(struct vsock_sock
*vsk
,
101 size_t target
, struct vsock_transport_recv_notify_data
*data
);
102 int virtio_transport_notify_recv_post_dequeue(struct vsock_sock
*vsk
,
103 size_t target
, ssize_t copied
, bool data_read
,
104 struct vsock_transport_recv_notify_data
*data
);
105 int virtio_transport_notify_send_init(struct vsock_sock
*vsk
,
106 struct vsock_transport_send_notify_data
*data
);
107 int virtio_transport_notify_send_pre_block(struct vsock_sock
*vsk
,
108 struct vsock_transport_send_notify_data
*data
);
109 int virtio_transport_notify_send_pre_enqueue(struct vsock_sock
*vsk
,
110 struct vsock_transport_send_notify_data
*data
);
111 int virtio_transport_notify_send_post_enqueue(struct vsock_sock
*vsk
,
112 ssize_t written
, struct vsock_transport_send_notify_data
*data
);
113 void virtio_transport_notify_buffer_size(struct vsock_sock
*vsk
, u64
*val
);
115 u64
virtio_transport_stream_rcvhiwat(struct vsock_sock
*vsk
);
116 bool virtio_transport_stream_is_active(struct vsock_sock
*vsk
);
117 bool virtio_transport_stream_allow(u32 cid
, u32 port
);
118 int virtio_transport_dgram_bind(struct vsock_sock
*vsk
,
119 struct sockaddr_vm
*addr
);
120 bool virtio_transport_dgram_allow(u32 cid
, u32 port
);
122 int virtio_transport_connect(struct vsock_sock
*vsk
);
124 int virtio_transport_shutdown(struct vsock_sock
*vsk
, int mode
);
126 void virtio_transport_release(struct vsock_sock
*vsk
);
129 virtio_transport_stream_enqueue(struct vsock_sock
*vsk
,
133 virtio_transport_dgram_enqueue(struct vsock_sock
*vsk
,
134 struct sockaddr_vm
*remote_addr
,
138 void virtio_transport_destruct(struct vsock_sock
*vsk
);
140 void virtio_transport_recv_pkt(struct virtio_transport
*t
,
141 struct virtio_vsock_pkt
*pkt
);
142 void virtio_transport_free_pkt(struct virtio_vsock_pkt
*pkt
);
143 void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock
*vvs
, struct virtio_vsock_pkt
*pkt
);
144 u32
virtio_transport_get_credit(struct virtio_vsock_sock
*vvs
, u32 wanted
);
145 void virtio_transport_put_credit(struct virtio_vsock_sock
*vvs
, u32 credit
);
146 void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt
*pkt
);
148 #endif /* _LINUX_VIRTIO_VSOCK_H */