1 #ifndef _LINUX_VIRTIO_VSOCK_H
2 #define _LINUX_VIRTIO_VSOCK_H
4 #include <uapi/linux/virtio_vsock.h>
5 #include <linux/socket.h>
7 #include <net/af_vsock.h>
9 #define VIRTIO_VSOCK_DEFAULT_MIN_BUF_SIZE 128
10 #define VIRTIO_VSOCK_DEFAULT_BUF_SIZE (1024 * 256)
11 #define VIRTIO_VSOCK_DEFAULT_MAX_BUF_SIZE (1024 * 256)
12 #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4)
13 #define VIRTIO_VSOCK_MAX_BUF_SIZE 0xFFFFFFFFUL
14 #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
17 VSOCK_VQ_RX
= 0, /* for host to guest data */
18 VSOCK_VQ_TX
= 1, /* for guest to host data */
23 /* Per-socket state (accessed via vsk->trans) */
24 struct virtio_vsock_sock
{
25 struct vsock_sock
*vsk
;
27 /* Protected by lock_sock(sk_vsock(trans->vsk)) */
35 /* Protected by tx_lock */
41 /* Protected by rx_lock */
44 struct list_head rx_queue
;
47 struct virtio_vsock_pkt
{
48 struct virtio_vsock_hdr hdr
;
49 struct work_struct work
;
50 struct list_head list
;
51 /* socket refcnt not held, only use for cancellation */
52 struct vsock_sock
*vsk
;
59 struct virtio_vsock_pkt_info
{
60 u32 remote_cid
, remote_port
;
61 struct vsock_sock
*vsk
;
70 struct virtio_transport
{
71 /* This must be the first field */
72 struct vsock_transport transport
;
74 /* Takes ownership of the packet */
75 int (*send_pkt
)(struct virtio_vsock_pkt
*pkt
);
79 virtio_transport_stream_dequeue(struct vsock_sock
*vsk
,
84 virtio_transport_dgram_dequeue(struct vsock_sock
*vsk
,
86 size_t len
, int flags
);
88 s64
virtio_transport_stream_has_data(struct vsock_sock
*vsk
);
89 s64
virtio_transport_stream_has_space(struct vsock_sock
*vsk
);
91 int virtio_transport_do_socket_init(struct vsock_sock
*vsk
,
92 struct vsock_sock
*psk
);
93 u64
virtio_transport_get_buffer_size(struct vsock_sock
*vsk
);
94 u64
virtio_transport_get_min_buffer_size(struct vsock_sock
*vsk
);
95 u64
virtio_transport_get_max_buffer_size(struct vsock_sock
*vsk
);
96 void virtio_transport_set_buffer_size(struct vsock_sock
*vsk
, u64 val
);
97 void virtio_transport_set_min_buffer_size(struct vsock_sock
*vsk
, u64 val
);
98 void virtio_transport_set_max_buffer_size(struct vsock_sock
*vs
, u64 val
);
100 virtio_transport_notify_poll_in(struct vsock_sock
*vsk
,
102 bool *data_ready_now
);
104 virtio_transport_notify_poll_out(struct vsock_sock
*vsk
,
106 bool *space_available_now
);
108 int virtio_transport_notify_recv_init(struct vsock_sock
*vsk
,
109 size_t target
, struct vsock_transport_recv_notify_data
*data
);
110 int virtio_transport_notify_recv_pre_block(struct vsock_sock
*vsk
,
111 size_t target
, struct vsock_transport_recv_notify_data
*data
);
112 int virtio_transport_notify_recv_pre_dequeue(struct vsock_sock
*vsk
,
113 size_t target
, struct vsock_transport_recv_notify_data
*data
);
114 int virtio_transport_notify_recv_post_dequeue(struct vsock_sock
*vsk
,
115 size_t target
, ssize_t copied
, bool data_read
,
116 struct vsock_transport_recv_notify_data
*data
);
117 int virtio_transport_notify_send_init(struct vsock_sock
*vsk
,
118 struct vsock_transport_send_notify_data
*data
);
119 int virtio_transport_notify_send_pre_block(struct vsock_sock
*vsk
,
120 struct vsock_transport_send_notify_data
*data
);
121 int virtio_transport_notify_send_pre_enqueue(struct vsock_sock
*vsk
,
122 struct vsock_transport_send_notify_data
*data
);
123 int virtio_transport_notify_send_post_enqueue(struct vsock_sock
*vsk
,
124 ssize_t written
, struct vsock_transport_send_notify_data
*data
);
126 u64
virtio_transport_stream_rcvhiwat(struct vsock_sock
*vsk
);
127 bool virtio_transport_stream_is_active(struct vsock_sock
*vsk
);
128 bool virtio_transport_stream_allow(u32 cid
, u32 port
);
129 int virtio_transport_dgram_bind(struct vsock_sock
*vsk
,
130 struct sockaddr_vm
*addr
);
131 bool virtio_transport_dgram_allow(u32 cid
, u32 port
);
133 int virtio_transport_connect(struct vsock_sock
*vsk
);
135 int virtio_transport_shutdown(struct vsock_sock
*vsk
, int mode
);
137 void virtio_transport_release(struct vsock_sock
*vsk
);
140 virtio_transport_stream_enqueue(struct vsock_sock
*vsk
,
144 virtio_transport_dgram_enqueue(struct vsock_sock
*vsk
,
145 struct sockaddr_vm
*remote_addr
,
149 void virtio_transport_destruct(struct vsock_sock
*vsk
);
151 void virtio_transport_recv_pkt(struct virtio_vsock_pkt
*pkt
);
152 void virtio_transport_free_pkt(struct virtio_vsock_pkt
*pkt
);
153 void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock
*vvs
, struct virtio_vsock_pkt
*pkt
);
154 u32
virtio_transport_get_credit(struct virtio_vsock_sock
*vvs
, u32 wanted
);
155 void virtio_transport_put_credit(struct virtio_vsock_sock
*vvs
, u32 credit
);
156 void virtio_transport_deliver_tap_pkt(struct virtio_vsock_pkt
*pkt
);
158 #endif /* _LINUX_VIRTIO_VSOCK_H */