| 1 | #ifndef VHOST_NET_H |
| 2 | #define VHOST_NET_H |
| 3 | |
| 4 | #include "net/net.h" |
| 5 | #include "hw/virtio/virtio-features.h" |
| 6 | #include "hw/virtio/vhost-backend.h" |
| 7 | |
| 8 | struct vhost_net; |
| 9 | typedef struct vhost_net VHostNetState; |
| 10 | |
| 11 | typedef uint64_t (GetAckedFeatures)(NetClientState *nc); |
| 12 | typedef void (SaveAcketFeatures)(NetClientState *nc); |
| 13 | |
| 14 | typedef struct VhostNetOptions { |
| 15 | VhostBackendType backend_type; |
| 16 | NetClientState *net_backend; |
| 17 | uint32_t busyloop_timeout; |
| 18 | unsigned int nvqs; |
| 19 | const int *feature_bits; |
| 20 | int max_tx_queue_size; |
| 21 | bool is_vhost_user; |
| 22 | GetAckedFeatures *get_acked_features; |
| 23 | SaveAcketFeatures *save_acked_features; |
| 24 | void *opaque; |
| 25 | } VhostNetOptions; |
| 26 | |
| 27 | uint64_t vhost_net_get_max_queues(VHostNetState *net); |
| 28 | struct vhost_net *vhost_net_init(VhostNetOptions *options); |
| 29 | |
| 30 | int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, |
| 31 | int data_queue_pairs, int cvq); |
| 32 | void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, |
| 33 | int data_queue_pairs, int cvq); |
| 34 | |
| 35 | void vhost_net_cleanup(VHostNetState *net); |
| 36 | |
| 37 | void vhost_net_get_features_ex(VHostNetState *net, uint64_t *features); |
| 38 | static inline uint64_t vhost_net_get_features(VHostNetState *net, |
| 39 | uint64_t features) |
| 40 | { |
| 41 | uint64_t features_array[VIRTIO_FEATURES_NU64S]; |
| 42 | |
| 43 | virtio_features_from_u64(features_array, features); |
| 44 | vhost_net_get_features_ex(net, features_array); |
| 45 | return features_array[0]; |
| 46 | } |
| 47 | |
| 48 | void vhost_net_ack_features_ex(VHostNetState *net, const uint64_t *features); |
| 49 | static inline void vhost_net_ack_features(VHostNetState *net, |
| 50 | uint64_t features) |
| 51 | { |
| 52 | uint64_t features_array[VIRTIO_FEATURES_NU64S]; |
| 53 | |
| 54 | virtio_features_from_u64(features_array, features); |
| 55 | vhost_net_ack_features_ex(net, features_array); |
| 56 | } |
| 57 | |
| 58 | int vhost_net_get_config(struct vhost_net *net, uint8_t *config, |
| 59 | uint32_t config_len); |
| 60 | |
| 61 | int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, |
| 62 | uint32_t offset, uint32_t size, uint32_t flags); |
| 63 | bool vhost_net_virtqueue_pending(VHostNetState *net, int n); |
| 64 | void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, |
| 65 | int idx, bool mask); |
| 66 | bool vhost_net_config_pending(VHostNetState *net); |
| 67 | void vhost_net_config_mask(VHostNetState *net, VirtIODevice *dev, bool mask); |
| 68 | int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr); |
| 69 | VHostNetState *get_vhost_net(NetClientState *nc); |
| 70 | |
| 71 | int vhost_net_set_vring_enable(NetClientState *nc, int enable); |
| 72 | |
| 73 | void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *features); |
| 74 | static inline uint64_t vhost_net_get_acked_features(VHostNetState *net) |
| 75 | { |
| 76 | uint64_t features[VIRTIO_FEATURES_NU64S]; |
| 77 | |
| 78 | vhost_net_get_acked_features_ex(net, features); |
| 79 | assert(!virtio_features_use_ex(features)); |
| 80 | return features[0]; |
| 81 | } |
| 82 | |
| 83 | int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); |
| 84 | |
| 85 | void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc, |
| 86 | int vq_index); |
| 87 | int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc, |
| 88 | int vq_index); |
| 89 | |
| 90 | void vhost_net_save_acked_features(NetClientState *nc); |
| 91 | #endif |