Lines Matching +full:- +full:v

9  * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
14 * See the COPYING.LIB file in the top-level directory.
20 #include "qemu/error-report.h"
22 #include "hw/qdev-core.h"
23 #include "hw/qdev-properties.h"
24 #include "hw/qdev-properties-system.h"
27 #include "hw/virtio/virtio-bus.h"
28 #include "hw/virtio/vdpa-dev.h"
41 uint32_t val = (uint32_t)-1; in vhost_vdpa_device_get_u32()
44 error_setg(errp, "vhost-vdpa-device: cmd 0x%lx failed: %s", in vhost_vdpa_device_get_u32()
54 VhostVdpaDevice *v = VHOST_VDPA_DEVICE(vdev); in vhost_vdpa_device_realize() local
60 if (!v->vhostdev) { in vhost_vdpa_device_realize()
61 error_setg(errp, "vhost-vdpa-device: vhostdev are missing"); in vhost_vdpa_device_realize()
65 v->vhostfd = qemu_open(v->vhostdev, O_RDWR, errp); in vhost_vdpa_device_realize()
70 v->vdev_id = vhost_vdpa_device_get_u32(v->vhostfd, in vhost_vdpa_device_realize()
76 max_queue_size = vhost_vdpa_device_get_u32(v->vhostfd, in vhost_vdpa_device_realize()
82 if (v->queue_size > max_queue_size) { in vhost_vdpa_device_realize()
83 error_setg(errp, "vhost-vdpa-device: invalid queue_size: %u (max:%u)", in vhost_vdpa_device_realize()
84 v->queue_size, max_queue_size); in vhost_vdpa_device_realize()
86 } else if (!v->queue_size) { in vhost_vdpa_device_realize()
87 v->queue_size = max_queue_size; in vhost_vdpa_device_realize()
90 v->num_queues = vhost_vdpa_device_get_u32(v->vhostfd, in vhost_vdpa_device_realize()
96 if (!v->num_queues || v->num_queues > VIRTIO_QUEUE_MAX) { in vhost_vdpa_device_realize()
98 v->num_queues, VIRTIO_QUEUE_MAX); in vhost_vdpa_device_realize()
102 v->dev.nvqs = v->num_queues; in vhost_vdpa_device_realize()
103 vqs = g_new0(struct vhost_virtqueue, v->dev.nvqs); in vhost_vdpa_device_realize()
104 v->dev.vqs = vqs; in vhost_vdpa_device_realize()
105 v->dev.vq_index = 0; in vhost_vdpa_device_realize()
106 v->dev.vq_index_end = v->dev.nvqs; in vhost_vdpa_device_realize()
107 v->dev.backend_features = 0; in vhost_vdpa_device_realize()
108 v->started = false; in vhost_vdpa_device_realize()
110 ret = vhost_vdpa_get_iova_range(v->vhostfd, &iova_range); in vhost_vdpa_device_realize()
112 error_setg(errp, "vhost-vdpa-device: get iova range failed: %s", in vhost_vdpa_device_realize()
113 strerror(-ret)); in vhost_vdpa_device_realize()
116 v->vdpa.shared = g_new0(VhostVDPAShared, 1); in vhost_vdpa_device_realize()
117 v->vdpa.shared->device_fd = v->vhostfd; in vhost_vdpa_device_realize()
118 v->vdpa.shared->iova_range = iova_range; in vhost_vdpa_device_realize()
120 ret = vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, NULL); in vhost_vdpa_device_realize()
122 error_setg(errp, "vhost-vdpa-device: vhost initialization failed: %s", in vhost_vdpa_device_realize()
123 strerror(-ret)); in vhost_vdpa_device_realize()
127 v->config_size = vhost_vdpa_device_get_u32(v->vhostfd, in vhost_vdpa_device_realize()
135 * Invoke .post_init() to initialize the transport-specific fields in vhost_vdpa_device_realize()
138 if (v->post_init && v->post_init(v, errp) < 0) { in vhost_vdpa_device_realize()
142 v->config = g_malloc0(v->config_size); in vhost_vdpa_device_realize()
144 ret = vhost_dev_get_config(&v->dev, v->config, v->config_size, NULL); in vhost_vdpa_device_realize()
146 error_setg(errp, "vhost-vdpa-device: get config failed"); in vhost_vdpa_device_realize()
150 virtio_init(vdev, v->vdev_id, v->config_size); in vhost_vdpa_device_realize()
152 v->virtqs = g_new0(VirtQueue *, v->dev.nvqs); in vhost_vdpa_device_realize()
153 for (i = 0; i < v->dev.nvqs; i++) { in vhost_vdpa_device_realize()
154 v->virtqs[i] = virtio_add_queue(vdev, v->queue_size, in vhost_vdpa_device_realize()
161 g_free(v->config); in vhost_vdpa_device_realize()
163 vhost_dev_cleanup(&v->dev); in vhost_vdpa_device_realize()
166 g_free(v->vdpa.shared); in vhost_vdpa_device_realize()
168 qemu_close(v->vhostfd); in vhost_vdpa_device_realize()
169 v->vhostfd = -1; in vhost_vdpa_device_realize()
180 for (i = 0; i < s->num_queues; i++) { in vhost_vdpa_device_unrealize()
181 virtio_delete_queue(s->virtqs[i]); in vhost_vdpa_device_unrealize()
183 g_free(s->virtqs); in vhost_vdpa_device_unrealize()
186 g_free(s->config); in vhost_vdpa_device_unrealize()
187 g_free(s->dev.vqs); in vhost_vdpa_device_unrealize()
188 vhost_dev_cleanup(&s->dev); in vhost_vdpa_device_unrealize()
189 g_free(s->vdpa.shared); in vhost_vdpa_device_unrealize()
190 qemu_close(s->vhostfd); in vhost_vdpa_device_unrealize()
191 s->vhostfd = -1; in vhost_vdpa_device_unrealize()
200 ret = vhost_dev_get_config(&s->dev, s->config, s->config_size, in vhost_vdpa_device_get_config()
206 memcpy(config, s->config, s->config_size); in vhost_vdpa_device_get_config()
215 ret = vhost_dev_set_config(&s->dev, s->config, 0, s->config_size, in vhost_vdpa_device_set_config()
228 uint64_t backend_features = s->dev.features; in vhost_vdpa_device_get_features()
244 if (!k->set_guest_notifiers) { in vhost_vdpa_device_start()
246 return -ENOSYS; in vhost_vdpa_device_start()
249 ret = vhost_dev_enable_notifiers(&s->dev, vdev); in vhost_vdpa_device_start()
251 error_setg_errno(errp, -ret, "Error enabling host notifiers"); in vhost_vdpa_device_start()
255 ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); in vhost_vdpa_device_start()
257 error_setg_errno(errp, -ret, "Error binding guest notifier"); in vhost_vdpa_device_start()
261 s->dev.acked_features = vdev->guest_features; in vhost_vdpa_device_start()
263 ret = vhost_dev_start(&s->dev, vdev, true); in vhost_vdpa_device_start()
265 error_setg_errno(errp, -ret, "Error starting vhost"); in vhost_vdpa_device_start()
268 s->started = true; in vhost_vdpa_device_start()
272 * everything here. virtio-pci will do the right thing by in vhost_vdpa_device_start()
275 for (i = 0; i < s->dev.nvqs; i++) { in vhost_vdpa_device_start()
276 vhost_virtqueue_mask(&s->dev, vdev, i, false); in vhost_vdpa_device_start()
282 k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); in vhost_vdpa_device_start()
284 vhost_dev_disable_notifiers(&s->dev, vdev); in vhost_vdpa_device_start()
295 if (!s->started) { in vhost_vdpa_device_stop()
298 s->started = false; in vhost_vdpa_device_stop()
300 if (!k->set_guest_notifiers) { in vhost_vdpa_device_stop()
304 vhost_dev_stop(&s->dev, vdev, false); in vhost_vdpa_device_stop()
306 ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); in vhost_vdpa_device_stop()
312 vhost_dev_disable_notifiers(&s->dev, vdev); in vhost_vdpa_device_stop()
322 if (!vdev->vm_running) { in vhost_vdpa_device_set_status()
326 if (s->started == should_start) { in vhost_vdpa_device_set_status()
333 error_reportf_err(local_err, "vhost-vdpa-device: start failed: "); in vhost_vdpa_device_set_status()
343 DEFINE_PROP_UINT16("queue-size", VhostVdpaDevice, queue_size, 0),
347 .name = "vhost-vdpa-device",
363 dc->desc = "VDPA-based generic device assignment"; in vhost_vdpa_device_class_init()
364 dc->vmsd = &vmstate_vhost_vdpa_device; in vhost_vdpa_device_class_init()
365 set_bit(DEVICE_CATEGORY_MISC, dc->categories); in vhost_vdpa_device_class_init()
366 vdc->realize = vhost_vdpa_device_realize; in vhost_vdpa_device_class_init()
367 vdc->unrealize = vhost_vdpa_device_unrealize; in vhost_vdpa_device_class_init()
368 vdc->get_config = vhost_vdpa_device_get_config; in vhost_vdpa_device_class_init()
369 vdc->set_config = vhost_vdpa_device_set_config; in vhost_vdpa_device_class_init()
370 vdc->get_features = vhost_vdpa_device_get_features; in vhost_vdpa_device_class_init()
371 vdc->set_status = vhost_vdpa_device_set_status; in vhost_vdpa_device_class_init()
378 device_add_bootindex_property(obj, &s->bootindex, "bootindex", in vhost_vdpa_device_instance_init()