1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
12 #include <sys/eventfd.h>
13 #include <sys/types.h>
16 #include <rte_string_fns.h>
17 #include <rte_eal_memconfig.h>
20 #include "virtio_user_dev.h"
21 #include "../virtio_ethdev.h"
23 #define VIRTIO_USER_MEM_EVENT_CLB_NAME "virtio_user_mem_event_clb"
26 virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
28 /* Of all per virtqueue MSGs, make sure VHOST_SET_VRING_CALL come
29 * firstly because vhost depends on this msg to allocate virtqueue
32 struct vhost_vring_file file;
34 file.index = queue_sel;
35 file.fd = dev->callfds[queue_sel];
36 dev->ops->send_request(dev, VHOST_USER_SET_VRING_CALL, &file);
42 virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
44 struct vhost_vring_file file;
45 struct vhost_vring_state state;
46 struct vring *vring = &dev->vrings[queue_sel];
47 struct vring_packed *pq_vring = &dev->packed_vrings[queue_sel];
48 struct vhost_vring_addr addr = {
51 .flags = 0, /* disable log */
54 if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
56 (uint64_t)(uintptr_t)pq_vring->desc;
57 addr.avail_user_addr =
58 (uint64_t)(uintptr_t)pq_vring->driver;
60 (uint64_t)(uintptr_t)pq_vring->device;
62 addr.desc_user_addr = (uint64_t)(uintptr_t)vring->desc;
63 addr.avail_user_addr = (uint64_t)(uintptr_t)vring->avail;
64 addr.used_user_addr = (uint64_t)(uintptr_t)vring->used;
67 state.index = queue_sel;
68 state.num = vring->num;
69 dev->ops->send_request(dev, VHOST_USER_SET_VRING_NUM, &state);
71 state.index = queue_sel;
72 state.num = 0; /* no reservation */
73 if (dev->features & (1ULL << VIRTIO_F_RING_PACKED))
74 state.num |= (1 << 15);
75 dev->ops->send_request(dev, VHOST_USER_SET_VRING_BASE, &state);
77 dev->ops->send_request(dev, VHOST_USER_SET_VRING_ADDR, &addr);
79 /* Of all per virtqueue MSGs, make sure VHOST_USER_SET_VRING_KICK comes
80 * lastly because vhost depends on this msg to judge if
83 file.index = queue_sel;
84 file.fd = dev->kickfds[queue_sel];
85 dev->ops->send_request(dev, VHOST_USER_SET_VRING_KICK, &file);
91 virtio_user_queue_setup(struct virtio_user_dev *dev,
92 int (*fn)(struct virtio_user_dev *, uint32_t))
94 uint32_t i, queue_sel;
96 for (i = 0; i < dev->max_queue_pairs; ++i) {
97 queue_sel = 2 * i + VTNET_SQ_RQ_QUEUE_IDX;
98 if (fn(dev, queue_sel) < 0) {
99 PMD_DRV_LOG(INFO, "setup rx vq fails: %u", i);
103 for (i = 0; i < dev->max_queue_pairs; ++i) {
104 queue_sel = 2 * i + VTNET_SQ_TQ_QUEUE_IDX;
105 if (fn(dev, queue_sel) < 0) {
106 PMD_DRV_LOG(INFO, "setup tx vq fails: %u", i);
115 virtio_user_dev_set_features(struct virtio_user_dev *dev)
120 pthread_mutex_lock(&dev->mutex);
122 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER &&
126 /* Step 0: tell vhost to create queues */
127 if (virtio_user_queue_setup(dev, virtio_user_create_queue) < 0)
130 features = dev->features;
132 /* Strip VIRTIO_NET_F_MAC, as MAC address is handled in vdev init */
133 features &= ~(1ull << VIRTIO_NET_F_MAC);
134 /* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */
135 features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ);
136 features &= ~(1ull << VIRTIO_NET_F_STATUS);
137 ret = dev->ops->send_request(dev, VHOST_USER_SET_FEATURES, &features);
140 PMD_DRV_LOG(INFO, "set features: %" PRIx64, features);
142 pthread_mutex_unlock(&dev->mutex);
148 virtio_user_start_device(struct virtio_user_dev *dev)
155 * We need to make sure that the locks will be
156 * taken in the correct order to avoid deadlocks.
158 * Before releasing this lock, this thread should
159 * not trigger any memory hotplug events.
161 * This is a temporary workaround, and should be
162 * replaced when we get proper supports from the
163 * memory subsystem in the future.
165 rte_mcfg_mem_read_lock();
166 pthread_mutex_lock(&dev->mutex);
168 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER &&
172 /* Step 2: share memory regions */
173 ret = dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL);
177 /* Step 3: kick queues */
178 if (virtio_user_queue_setup(dev, virtio_user_kick_queue) < 0)
181 /* Step 4: enable queues
182 * we enable the 1st queue pair by default.
184 dev->ops->enable_qp(dev, 0, 1);
187 pthread_mutex_unlock(&dev->mutex);
188 rte_mcfg_mem_read_unlock();
192 pthread_mutex_unlock(&dev->mutex);
193 rte_mcfg_mem_read_unlock();
194 /* TODO: free resource here or caller to check */
198 int virtio_user_stop_device(struct virtio_user_dev *dev)
200 struct vhost_vring_state state;
204 pthread_mutex_lock(&dev->mutex);
208 for (i = 0; i < dev->max_queue_pairs; ++i)
209 dev->ops->enable_qp(dev, i, 0);
211 /* Stop the backend. */
212 for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
214 if (dev->ops->send_request(dev, VHOST_USER_GET_VRING_BASE,
216 PMD_DRV_LOG(ERR, "get_vring_base failed, index=%u\n",
223 dev->started = false;
225 pthread_mutex_unlock(&dev->mutex);
231 parse_mac(struct virtio_user_dev *dev, const char *mac)
233 struct rte_ether_addr tmp;
238 if (rte_ether_unformat_addr(mac, &tmp) == 0) {
239 memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN);
240 dev->mac_specified = 1;
242 /* ignore the wrong mac, use random mac */
243 PMD_DRV_LOG(ERR, "wrong format of mac: %s", mac);
248 virtio_user_dev_init_notify(struct virtio_user_dev *dev)
254 for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
255 if (i >= dev->max_queue_pairs * 2) {
256 dev->kickfds[i] = -1;
257 dev->callfds[i] = -1;
261 /* May use invalid flag, but some backend uses kickfd and
262 * callfd as criteria to judge if dev is alive. so finally we
265 callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
267 PMD_DRV_LOG(ERR, "callfd error, %s", strerror(errno));
270 kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
272 PMD_DRV_LOG(ERR, "kickfd error, %s", strerror(errno));
275 dev->callfds[i] = callfd;
276 dev->kickfds[i] = kickfd;
279 if (i < VIRTIO_MAX_VIRTQUEUES) {
280 for (j = 0; j <= i; ++j) {
281 close(dev->callfds[j]);
282 close(dev->kickfds[j]);
292 virtio_user_fill_intr_handle(struct virtio_user_dev *dev)
295 struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
297 if (!eth_dev->intr_handle) {
298 eth_dev->intr_handle = malloc(sizeof(*eth_dev->intr_handle));
299 if (!eth_dev->intr_handle) {
300 PMD_DRV_LOG(ERR, "fail to allocate intr_handle");
303 memset(eth_dev->intr_handle, 0, sizeof(*eth_dev->intr_handle));
306 for (i = 0; i < dev->max_queue_pairs; ++i)
307 eth_dev->intr_handle->efds[i] = dev->callfds[i];
308 eth_dev->intr_handle->nb_efd = dev->max_queue_pairs;
309 eth_dev->intr_handle->max_intr = dev->max_queue_pairs + 1;
310 eth_dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;
311 /* For virtio vdev, no need to read counter for clean */
312 eth_dev->intr_handle->efd_counter_size = 0;
313 eth_dev->intr_handle->fd = -1;
314 if (dev->vhostfd >= 0)
315 eth_dev->intr_handle->fd = dev->vhostfd;
316 else if (dev->is_server)
317 eth_dev->intr_handle->fd = dev->listenfd;
323 virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,
325 size_t len __rte_unused,
328 struct virtio_user_dev *dev = arg;
329 struct rte_memseg_list *msl;
332 /* ignore externally allocated memory */
333 msl = rte_mem_virt2memseg_list(addr);
337 pthread_mutex_lock(&dev->mutex);
339 if (dev->started == false)
342 /* Step 1: pause the active queues */
343 for (i = 0; i < dev->queue_pairs; i++)
344 dev->ops->enable_qp(dev, i, 0);
346 /* Step 2: update memory regions */
347 dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL);
349 /* Step 3: resume the active queues */
350 for (i = 0; i < dev->queue_pairs; i++)
351 dev->ops->enable_qp(dev, i, 1);
354 pthread_mutex_unlock(&dev->mutex);
358 virtio_user_dev_setup(struct virtio_user_dev *dev)
363 dev->vhostfds = NULL;
366 if (dev->is_server) {
367 if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER) {
368 PMD_DRV_LOG(ERR, "Server mode only supports vhost-user!");
371 dev->ops = &virtio_ops_user;
373 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) {
374 dev->ops = &virtio_ops_user;
375 } else if (dev->backend_type ==
376 VIRTIO_USER_BACKEND_VHOST_KERNEL) {
377 dev->ops = &virtio_ops_kernel;
379 dev->vhostfds = malloc(dev->max_queue_pairs *
381 dev->tapfds = malloc(dev->max_queue_pairs *
383 if (!dev->vhostfds || !dev->tapfds) {
384 PMD_INIT_LOG(ERR, "Failed to malloc");
388 for (q = 0; q < dev->max_queue_pairs; ++q) {
389 dev->vhostfds[q] = -1;
395 if (dev->ops->setup(dev) < 0)
398 if (virtio_user_dev_init_notify(dev) < 0)
401 if (virtio_user_fill_intr_handle(dev) < 0)
407 /* Use below macro to filter features from vhost backend */
408 #define VIRTIO_USER_SUPPORTED_FEATURES \
409 (1ULL << VIRTIO_NET_F_MAC | \
410 1ULL << VIRTIO_NET_F_STATUS | \
411 1ULL << VIRTIO_NET_F_MQ | \
412 1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR | \
413 1ULL << VIRTIO_NET_F_CTRL_VQ | \
414 1ULL << VIRTIO_NET_F_CTRL_RX | \
415 1ULL << VIRTIO_NET_F_CTRL_VLAN | \
416 1ULL << VIRTIO_NET_F_CSUM | \
417 1ULL << VIRTIO_NET_F_HOST_TSO4 | \
418 1ULL << VIRTIO_NET_F_HOST_TSO6 | \
419 1ULL << VIRTIO_NET_F_MRG_RXBUF | \
420 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \
421 1ULL << VIRTIO_NET_F_GUEST_CSUM | \
422 1ULL << VIRTIO_NET_F_GUEST_TSO4 | \
423 1ULL << VIRTIO_NET_F_GUEST_TSO6 | \
424 1ULL << VIRTIO_F_IN_ORDER | \
425 1ULL << VIRTIO_F_VERSION_1 | \
426 1ULL << VIRTIO_F_RING_PACKED | \
427 1ULL << VHOST_USER_F_PROTOCOL_FEATURES)
429 #define VIRTIO_USER_SUPPORTED_PROTOCOL_FEATURES \
430 (1ULL << VHOST_USER_PROTOCOL_F_MQ | \
431 1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK | \
432 1ULL << VHOST_USER_PROTOCOL_F_STATUS)
435 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
436 int cq, int queue_size, const char *mac, char **ifname,
437 int server, int mrg_rxbuf, int in_order, int packed_vq,
438 enum virtio_user_backend_type backend_type)
440 uint64_t protocol_features = 0;
442 pthread_mutex_init(&dev->mutex, NULL);
443 strlcpy(dev->path, path, PATH_MAX);
445 dev->max_queue_pairs = queues;
446 dev->queue_pairs = 1; /* mq disabled by default */
447 dev->queue_size = queue_size;
448 dev->is_server = server;
449 dev->mac_specified = 0;
450 dev->frontend_features = 0;
451 dev->unsupported_features = ~VIRTIO_USER_SUPPORTED_FEATURES;
452 dev->protocol_features = VIRTIO_USER_SUPPORTED_PROTOCOL_FEATURES;
453 dev->backend_type = backend_type;
458 dev->ifname = *ifname;
462 if (virtio_user_dev_setup(dev) < 0) {
463 PMD_INIT_LOG(ERR, "backend set up fails");
467 if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
468 dev->unsupported_features |=
469 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
471 if (!dev->is_server) {
472 if (dev->ops->send_request(dev, VHOST_USER_SET_OWNER,
474 PMD_INIT_LOG(ERR, "set_owner fails: %s",
479 if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
480 &dev->device_features) < 0) {
481 PMD_INIT_LOG(ERR, "get_features failed: %s",
487 if (dev->device_features &
488 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) {
489 if (dev->ops->send_request(dev,
490 VHOST_USER_GET_PROTOCOL_FEATURES,
494 dev->protocol_features &= protocol_features;
496 if (dev->ops->send_request(dev,
497 VHOST_USER_SET_PROTOCOL_FEATURES,
498 &dev->protocol_features))
501 if (!(dev->protocol_features &
502 (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
503 dev->unsupported_features |=
504 (1ull << VIRTIO_NET_F_MQ);
507 /* We just pretend vhost-user can support all these features.
508 * Note that this could be problematic that if some feature is
509 * negotiated but not supported by the vhost-user which comes
512 dev->device_features = VIRTIO_USER_SUPPORTED_FEATURES;
518 dev->unsupported_features |= (1ull << VIRTIO_NET_F_MRG_RXBUF);
521 dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
524 dev->unsupported_features |= (1ull << VIRTIO_F_RING_PACKED);
526 if (dev->mac_specified)
527 dev->frontend_features |= (1ull << VIRTIO_NET_F_MAC);
529 dev->unsupported_features |= (1ull << VIRTIO_NET_F_MAC);
532 /* device does not really need to know anything about CQ,
533 * so if necessary, we just claim to support CQ
535 dev->frontend_features |= (1ull << VIRTIO_NET_F_CTRL_VQ);
537 dev->unsupported_features |= (1ull << VIRTIO_NET_F_CTRL_VQ);
538 /* Also disable features that depend on VIRTIO_NET_F_CTRL_VQ */
539 dev->unsupported_features |= (1ull << VIRTIO_NET_F_CTRL_RX);
540 dev->unsupported_features |= (1ull << VIRTIO_NET_F_CTRL_VLAN);
541 dev->unsupported_features |=
542 (1ull << VIRTIO_NET_F_GUEST_ANNOUNCE);
543 dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
544 dev->unsupported_features |=
545 (1ull << VIRTIO_NET_F_CTRL_MAC_ADDR);
548 /* The backend will not report this feature, we add it explicitly */
549 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER)
550 dev->frontend_features |= (1ull << VIRTIO_NET_F_STATUS);
554 * (frontend_features | backend_features) & ~unsupported_features;
556 dev->device_features |= dev->frontend_features;
557 dev->device_features &= ~dev->unsupported_features;
559 if (rte_mem_event_callback_register(VIRTIO_USER_MEM_EVENT_CLB_NAME,
560 virtio_user_mem_event_cb, dev)) {
561 if (rte_errno != ENOTSUP) {
562 PMD_INIT_LOG(ERR, "Failed to register mem event"
572 virtio_user_dev_uninit(struct virtio_user_dev *dev)
576 virtio_user_stop_device(dev);
578 rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
580 for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
581 close(dev->callfds[i]);
582 close(dev->kickfds[i]);
585 if (dev->vhostfd >= 0)
588 if (dev->is_server && dev->listenfd >= 0) {
589 close(dev->listenfd);
594 for (i = 0; i < dev->max_queue_pairs; ++i) {
595 close(dev->vhostfds[i]);
596 if (dev->tapfds[i] >= 0)
597 close(dev->tapfds[i]);
610 virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
615 if (q_pairs > dev->max_queue_pairs) {
616 PMD_INIT_LOG(ERR, "multi-q config %u, but only %u supported",
617 q_pairs, dev->max_queue_pairs);
621 /* Server mode can't enable queue pairs if vhostfd is invalid,
622 * always return 0 in this case.
624 if (!dev->is_server || dev->vhostfd >= 0) {
625 for (i = 0; i < q_pairs; ++i)
626 ret |= dev->ops->enable_qp(dev, i, 1);
627 for (i = q_pairs; i < dev->max_queue_pairs; ++i)
628 ret |= dev->ops->enable_qp(dev, i, 0);
630 dev->queue_pairs = q_pairs;
636 virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, struct vring *vring,
639 struct virtio_net_ctrl_hdr *hdr;
640 virtio_net_ctrl_ack status = ~0;
641 uint16_t i, idx_data, idx_status;
642 uint32_t n_descs = 0;
644 /* locate desc for header, data, and status */
645 idx_data = vring->desc[idx_hdr].next;
649 while (vring->desc[i].flags == VRING_DESC_F_NEXT) {
650 i = vring->desc[i].next;
654 /* locate desc for status */
658 hdr = (void *)(uintptr_t)vring->desc[idx_hdr].addr;
659 if (hdr->class == VIRTIO_NET_CTRL_MQ &&
660 hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
663 queues = *(uint16_t *)(uintptr_t)vring->desc[idx_data].addr;
664 status = virtio_user_handle_mq(dev, queues);
665 } else if (hdr->class == VIRTIO_NET_CTRL_RX ||
666 hdr->class == VIRTIO_NET_CTRL_MAC ||
667 hdr->class == VIRTIO_NET_CTRL_VLAN) {
672 *(virtio_net_ctrl_ack *)(uintptr_t)vring->desc[idx_status].addr = status;
678 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
680 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
682 return wrap_counter == !!(flags & VRING_PACKED_DESC_F_AVAIL) &&
683 wrap_counter != !!(flags & VRING_PACKED_DESC_F_USED);
687 virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
688 struct vring_packed *vring,
691 struct virtio_net_ctrl_hdr *hdr;
692 virtio_net_ctrl_ack status = ~0;
693 uint16_t idx_data, idx_status;
694 /* initialize to one, header is first */
695 uint32_t n_descs = 1;
697 /* locate desc for header, data, and status */
698 idx_data = idx_hdr + 1;
699 if (idx_data >= dev->queue_size)
700 idx_data -= dev->queue_size;
704 idx_status = idx_data;
705 while (vring->desc[idx_status].flags & VRING_DESC_F_NEXT) {
707 if (idx_status >= dev->queue_size)
708 idx_status -= dev->queue_size;
712 hdr = (void *)(uintptr_t)vring->desc[idx_hdr].addr;
713 if (hdr->class == VIRTIO_NET_CTRL_MQ &&
714 hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
717 queues = *(uint16_t *)(uintptr_t)
718 vring->desc[idx_data].addr;
719 status = virtio_user_handle_mq(dev, queues);
720 } else if (hdr->class == VIRTIO_NET_CTRL_RX ||
721 hdr->class == VIRTIO_NET_CTRL_MAC ||
722 hdr->class == VIRTIO_NET_CTRL_VLAN) {
727 *(virtio_net_ctrl_ack *)(uintptr_t)
728 vring->desc[idx_status].addr = status;
730 /* Update used descriptor */
731 vring->desc[idx_hdr].id = vring->desc[idx_status].id;
732 vring->desc[idx_hdr].len = sizeof(status);
738 virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
740 struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
741 struct vring_packed *vring = &dev->packed_vrings[queue_idx];
742 uint16_t n_descs, flags;
744 /* Perform a load-acquire barrier in desc_is_avail to
745 * enforce the ordering between desc flags and desc
748 while (desc_is_avail(&vring->desc[vq->used_idx],
749 vq->used_wrap_counter)) {
751 n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
754 flags = VRING_DESC_F_WRITE;
755 if (vq->used_wrap_counter)
756 flags |= VRING_PACKED_DESC_F_AVAIL_USED;
758 __atomic_store_n(&vring->desc[vq->used_idx].flags, flags,
761 vq->used_idx += n_descs;
762 if (vq->used_idx >= dev->queue_size) {
763 vq->used_idx -= dev->queue_size;
764 vq->used_wrap_counter ^= 1;
770 virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx)
772 uint16_t avail_idx, desc_idx;
773 struct vring_used_elem *uep;
775 struct vring *vring = &dev->vrings[queue_idx];
777 /* Consume avail ring, using used ring idx as first one */
778 while (__atomic_load_n(&vring->used->idx, __ATOMIC_RELAXED)
779 != vring->avail->idx) {
780 avail_idx = __atomic_load_n(&vring->used->idx, __ATOMIC_RELAXED)
782 desc_idx = vring->avail->ring[avail_idx];
784 n_descs = virtio_user_handle_ctrl_msg(dev, vring, desc_idx);
786 /* Update used ring */
787 uep = &vring->used->ring[avail_idx];
791 __atomic_add_fetch(&vring->used->idx, 1, __ATOMIC_RELAXED);
796 virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status)
799 uint64_t arg = status;
801 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER)
802 ret = dev->ops->send_request(dev,
803 VHOST_USER_SET_STATUS, &arg);
804 else if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA)
805 ret = dev->ops->send_request(dev,
806 VHOST_USER_SET_STATUS, &status);
811 PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret,
820 virtio_user_update_status(struct virtio_user_dev *dev)
826 if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) {
827 err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret);
828 if (!err && ret > UINT8_MAX) {
829 PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS "
830 "response 0x%" PRIx64 "\n", ret);
835 } else if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA) {
836 err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS,
843 PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err,
848 dev->status = status;
849 PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n"
851 "\t-ACKNOWLEDGE: %u\n"
854 "\t-FEATURES_OK: %u\n"
855 "\t-DEVICE_NEED_RESET: %u\n"
858 (dev->status == VIRTIO_CONFIG_STATUS_RESET),
859 !!(dev->status & VIRTIO_CONFIG_STATUS_ACK),
860 !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER),
861 !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK),
862 !!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK),
863 !!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET),
864 !!(dev->status & VIRTIO_CONFIG_STATUS_FAILED));