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;
54 struct virtio_vsock_pkt_info {
55 u32 remote_cid, remote_port;
56 struct vsock_sock *vsk;
65 struct virtio_transport {
66 /* This must be the first field */
67 struct vsock_transport transport;
69 /* Takes ownership of the packet */
70 int (*send_pkt)(struct virtio_vsock_pkt *pkt);
74 virtio_transport_stream_dequeue(struct vsock_sock *vsk,
79 virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
81 size_t len, int flags);
83 s64 virtio_transport_stream_has_data(struct vsock_sock *vsk);
84 s64 virtio_transport_stream_has_space(struct vsock_sock *vsk);
86 int virtio_transport_do_socket_init(struct vsock_sock *vsk,
87 struct vsock_sock *psk);
89 virtio_transport_notify_poll_in(struct vsock_sock *vsk,
91 bool *data_ready_now);
93 virtio_transport_notify_poll_out(struct vsock_sock *vsk,
95 bool *space_available_now);
97 int virtio_transport_notify_recv_init(struct vsock_sock *vsk,
98 size_t target, struct vsock_transport_recv_notify_data *data);
99 int virtio_transport_notify_recv_pre_block(struct vsock_sock *vsk,
100 size_t target, struct vsock_transport_recv_notify_data *data);
101 int virtio_transport_notify_recv_pre_dequeue(struct vsock_sock *vsk,
102 size_t target, struct vsock_transport_recv_notify_data *data);
103 int 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);
106 int virtio_transport_notify_send_init(struct vsock_sock *vsk,
107 struct vsock_transport_send_notify_data *data);
108 int virtio_transport_notify_send_pre_block(struct vsock_sock *vsk,
109 struct vsock_transport_send_notify_data *data);
110 int virtio_transport_notify_send_pre_enqueue(struct vsock_sock *vsk,
111 struct vsock_transport_send_notify_data *data);
112 int virtio_transport_notify_send_post_enqueue(struct vsock_sock *vsk,
113 ssize_t written, struct vsock_transport_send_notify_data *data);
114 void virtio_transport_notify_buffer_size(struct vsock_sock *vsk, u64 *val);
116 u64 virtio_transport_stream_rcvhiwat(struct vsock_sock *vsk);
117 bool virtio_transport_stream_is_active(struct vsock_sock *vsk);
118 bool virtio_transport_stream_allow(u32 cid, u32 port);
119 int virtio_transport_dgram_bind(struct vsock_sock *vsk,
120 struct sockaddr_vm *addr);
121 bool virtio_transport_dgram_allow(u32 cid, u32 port);
123 int virtio_transport_connect(struct vsock_sock *vsk);
125 int virtio_transport_shutdown(struct vsock_sock *vsk, int mode);
127 void virtio_transport_release(struct vsock_sock *vsk);
130 virtio_transport_stream_enqueue(struct vsock_sock *vsk,
134 virtio_transport_dgram_enqueue(struct vsock_sock *vsk,
135 struct sockaddr_vm *remote_addr,
139 void virtio_transport_destruct(struct vsock_sock *vsk);
141 void virtio_transport_recv_pkt(struct virtio_transport *t,
142 struct virtio_vsock_pkt *pkt);
143 void virtio_transport_free_pkt(struct virtio_vsock_pkt *pkt);
144 void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsock_pkt *pkt);
145 u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted);
146 void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit);
147 void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt *pkt);
149 #endif /* _LINUX_VIRTIO_VSOCK_H */