Lines Matching full:net
2 * vhost-net support
17 #include "net/net.h"
18 #include "net/tap.h"
19 #include "net/vhost-user.h"
20 #include "net/vhost-vdpa.h"
23 #include "hw/virtio/virtio-net.h"
24 #include "net/vhost_net.h"
30 #include <net/if.h>
99 static const int *vhost_net_get_feature_bits(struct vhost_net *net) in vhost_net_get_feature_bits() argument
103 switch (net->nc->info->type) { in vhost_net_get_feature_bits()
117 net->nc->info->type); in vhost_net_get_feature_bits()
124 uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) in vhost_net_get_features() argument
126 return vhost_get_features(&net->dev, vhost_net_get_feature_bits(net), in vhost_net_get_features()
129 int vhost_net_get_config(struct vhost_net *net, uint8_t *config, in vhost_net_get_config() argument
132 return vhost_dev_get_config(&net->dev, config, config_len, NULL); in vhost_net_get_config()
134 int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, in vhost_net_set_config() argument
137 return vhost_dev_set_config(&net->dev, data, offset, size, flags); in vhost_net_set_config()
140 void vhost_net_ack_features(struct vhost_net *net, uint64_t features) in vhost_net_ack_features() argument
142 net->dev.acked_features = net->dev.backend_features; in vhost_net_ack_features()
143 vhost_ack_features(&net->dev, vhost_net_get_feature_bits(net), features); in vhost_net_ack_features()
146 uint64_t vhost_net_get_max_queues(VHostNetState *net) in vhost_net_get_max_queues() argument
148 return net->dev.max_queues; in vhost_net_get_max_queues()
151 uint64_t vhost_net_get_acked_features(VHostNetState *net) in vhost_net_get_acked_features() argument
153 return net->dev.acked_features; in vhost_net_get_acked_features()
170 struct vhost_net *net; in vhost_net_disable_notifiers_nvhosts() local
188 net = get_vhost_net(peer); in vhost_net_disable_notifiers_nvhosts()
189 hdev = &net->dev; in vhost_net_disable_notifiers_nvhosts()
214 net = get_vhost_net(peer); in vhost_net_disable_notifiers_nvhosts()
215 hdev = &net->dev; in vhost_net_disable_notifiers_nvhosts()
230 struct vhost_net *net; in vhost_net_enable_notifiers() local
263 net = get_vhost_net(peer); in vhost_net_enable_notifiers()
264 hdev = &net->dev; in vhost_net_enable_notifiers()
313 fprintf(stderr, "vhost-net requires tap backend\n"); in vhost_net_get_fd()
322 struct vhost_net *net = g_new0(struct vhost_net, 1); in vhost_net_init() local
327 fprintf(stderr, "vhost-net requires net backend to be setup\n"); in vhost_net_init()
330 net->nc = options->net_backend; in vhost_net_init()
331 net->dev.nvqs = options->nvqs; in vhost_net_init()
333 net->dev.max_queues = 1; in vhost_net_init()
334 net->dev.vqs = net->vqs; in vhost_net_init()
341 net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend) in vhost_net_init()
343 net->backend = r; in vhost_net_init()
344 net->dev.protocol_features = 0; in vhost_net_init()
346 net->dev.backend_features = 0; in vhost_net_init()
347 net->dev.protocol_features = 0; in vhost_net_init()
348 net->backend = -1; in vhost_net_init()
351 net->dev.vq_index = net->nc->queue_index * net->dev.nvqs; in vhost_net_init()
354 r = vhost_dev_init(&net->dev, options->opaque, in vhost_net_init()
364 net->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); in vhost_net_init()
366 if (~net->dev.features & net->dev.backend_features) { in vhost_net_init()
369 (uint64_t)(~net->dev.features & net->dev.backend_features)); in vhost_net_init()
376 if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) { in vhost_net_init()
377 features = vhost_user_get_acked_features(net->nc); in vhost_net_init()
378 if (~net->dev.features & features) { in vhost_net_init()
381 (uint64_t)(~net->dev.features & features)); in vhost_net_init()
387 vhost_net_ack_features(net, features); in vhost_net_init()
389 return net; in vhost_net_init()
392 vhost_dev_cleanup(&net->dev); in vhost_net_init()
393 g_free(net); in vhost_net_init()
397 static void vhost_net_set_vq_index(struct vhost_net *net, int vq_index, in vhost_net_set_vq_index() argument
400 net->dev.vq_index = vq_index; in vhost_net_set_vq_index()
401 net->dev.vq_index_end = vq_index_end; in vhost_net_set_vq_index()
404 static int vhost_net_start_one(struct vhost_net *net, in vhost_net_start_one() argument
410 if (net->nc->info->start) { in vhost_net_start_one()
411 r = net->nc->info->start(net->nc); in vhost_net_start_one()
417 r = vhost_dev_start(&net->dev, dev, false); in vhost_net_start_one()
422 if (net->nc->info->poll) { in vhost_net_start_one()
423 net->nc->info->poll(net->nc, false); in vhost_net_start_one()
426 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_start_one()
427 qemu_set_fd_handler(net->backend, NULL, NULL, NULL); in vhost_net_start_one()
428 file.fd = net->backend; in vhost_net_start_one()
429 for (file.index = 0; file.index < net->dev.nvqs; ++file.index) { in vhost_net_start_one()
430 if (!virtio_queue_enabled(dev, net->dev.vq_index + in vhost_net_start_one()
435 r = vhost_net_set_backend(&net->dev, &file); in vhost_net_start_one()
443 if (net->nc->info->load) { in vhost_net_start_one()
444 r = net->nc->info->load(net->nc); in vhost_net_start_one()
452 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_start_one()
454 if (!virtio_queue_enabled(dev, net->dev.vq_index + in vhost_net_start_one()
459 int ret = vhost_net_set_backend(&net->dev, &file); in vhost_net_start_one()
463 if (net->nc->info->poll) { in vhost_net_start_one()
464 net->nc->info->poll(net->nc, true); in vhost_net_start_one()
466 vhost_dev_stop(&net->dev, dev, false); in vhost_net_start_one()
471 static void vhost_net_stop_one(struct vhost_net *net, in vhost_net_stop_one() argument
476 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_stop_one()
477 for (file.index = 0; file.index < net->dev.nvqs; ++file.index) { in vhost_net_stop_one()
478 int r = vhost_net_set_backend(&net->dev, &file); in vhost_net_stop_one()
482 if (net->nc->info->poll) { in vhost_net_stop_one()
483 net->nc->info->poll(net->nc, true); in vhost_net_stop_one()
485 vhost_dev_stop(&net->dev, dev, false); in vhost_net_stop_one()
486 if (net->nc->info->stop) { in vhost_net_stop_one()
487 net->nc->info->stop(net->nc); in vhost_net_stop_one()
500 struct vhost_net *net; in vhost_net_start() local
521 net = get_vhost_net(peer); in vhost_net_start()
522 vhost_net_set_vq_index(net, i * 2, index_end); in vhost_net_start()
528 if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) { in vhost_net_start()
617 void vhost_net_cleanup(struct vhost_net *net) in vhost_net_cleanup() argument
619 vhost_dev_cleanup(&net->dev); in vhost_net_cleanup()
622 int vhost_net_notify_migration_done(struct vhost_net *net, char* mac_addr) in vhost_net_notify_migration_done() argument
624 const VhostOps *vhost_ops = net->dev.vhost_ops; in vhost_net_notify_migration_done()
629 return vhost_ops->vhost_migration_done(&net->dev, mac_addr); in vhost_net_notify_migration_done()
632 bool vhost_net_virtqueue_pending(VHostNetState *net, int idx) in vhost_net_virtqueue_pending() argument
634 return vhost_virtqueue_pending(&net->dev, idx); in vhost_net_virtqueue_pending()
637 void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, in vhost_net_virtqueue_mask() argument
640 vhost_virtqueue_mask(&net->dev, dev, idx, mask); in vhost_net_virtqueue_mask()
643 bool vhost_net_config_pending(VHostNetState *net) in vhost_net_config_pending() argument
645 return vhost_config_pending(&net->dev); in vhost_net_config_pending()
648 void vhost_net_config_mask(VHostNetState *net, VirtIODevice *dev, bool mask) in vhost_net_config_mask() argument
650 vhost_config_mask(&net->dev, dev, mask); in vhost_net_config_mask()
664 * tap_get_vhost_net() can return NULL if a tap net-device backend is in get_vhost_net()
691 VHostNetState *net = get_vhost_net(nc); in vhost_set_vring_enable() local
692 const VhostOps *vhost_ops = net->dev.vhost_ops; in vhost_set_vring_enable()
698 * net/vhost-vdpa.c. in vhost_set_vring_enable()
707 return vhost_ops->vhost_set_vring_enable(&net->dev, enable); in vhost_set_vring_enable()
713 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) in vhost_net_set_mtu() argument
715 const VhostOps *vhost_ops = net->dev.vhost_ops; in vhost_net_set_mtu()
721 return vhost_ops->vhost_net_set_mtu(&net->dev, mtu); in vhost_net_set_mtu()
727 VHostNetState *net = get_vhost_net(nc->peer); in vhost_net_virtqueue_reset() local
728 const VhostOps *vhost_ops = net->dev.vhost_ops; in vhost_net_virtqueue_reset()
735 idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index); in vhost_net_virtqueue_reset()
737 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_virtqueue_reset()
739 int r = vhost_net_set_backend(&net->dev, &file); in vhost_net_virtqueue_reset()
743 vhost_virtqueue_stop(&net->dev, in vhost_net_virtqueue_reset()
745 net->dev.vqs + idx, in vhost_net_virtqueue_reset()
746 net->dev.vq_index + idx); in vhost_net_virtqueue_reset()
752 VHostNetState *net = get_vhost_net(nc->peer); in vhost_net_virtqueue_restart() local
753 const VhostOps *vhost_ops = net->dev.vhost_ops; in vhost_net_virtqueue_restart()
757 if (!net->dev.started) { in vhost_net_virtqueue_restart()
764 idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index); in vhost_net_virtqueue_restart()
766 r = vhost_virtqueue_start(&net->dev, in vhost_net_virtqueue_restart()
768 net->dev.vqs + idx, in vhost_net_virtqueue_restart()
769 net->dev.vq_index + idx); in vhost_net_virtqueue_restart()
774 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_virtqueue_restart()
776 file.fd = net->backend; in vhost_net_virtqueue_restart()
777 r = vhost_net_set_backend(&net->dev, &file); in vhost_net_virtqueue_restart()
789 if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) { in vhost_net_virtqueue_restart()
792 int ret = vhost_net_set_backend(&net->dev, &file); in vhost_net_virtqueue_restart()
796 vhost_dev_stop(&net->dev, vdev, false); in vhost_net_virtqueue_restart()