1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef _VHOST_NET_CDEV_H_
6 #define _VHOST_NET_CDEV_H_
10 #include <sys/types.h>
11 #include <sys/queue.h>
13 #include <linux/vhost.h>
14 #include <linux/virtio_net.h>
15 #include <sys/socket.h>
19 #include <rte_ether.h>
20 #include <rte_rwlock.h>
21 #include <rte_malloc.h>
23 #include "rte_vhost.h"
26 /* Used to indicate that the device is running on a data core */
27 #define VIRTIO_DEV_RUNNING 1
28 /* Used to indicate that the device is ready to operate */
29 #define VIRTIO_DEV_READY 2
30 /* Used to indicate that the built-in vhost net device backend is enabled */
31 #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
32 /* Used to indicate that the device has its own data path and configured */
33 #define VIRTIO_DEV_VDPA_CONFIGURED 8
35 /* Backend value set by guest. */
36 #define VIRTIO_DEV_STOPPED -1
38 #define BUF_VECTOR_MAX 256
40 #define VHOST_LOG_CACHE_NR 32
42 #define PACKED_DESC_ENQUEUE_USED_FLAG(w) \
43 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \
45 #define PACKED_DESC_DEQUEUE_USED_FLAG(w) \
46 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED) : 0x0)
47 #define PACKED_DESC_SINGLE_DEQUEUE_FLAG (VRING_DESC_F_NEXT | \
48 VRING_DESC_F_INDIRECT)
50 #define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \
51 sizeof(struct vring_packed_desc))
52 #define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
54 #ifdef VHOST_GCC_UNROLL_PRAGMA
55 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
56 for (iter = val; iter < size; iter++)
59 #ifdef VHOST_CLANG_UNROLL_PRAGMA
60 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
61 for (iter = val; iter < size; iter++)
64 #ifdef VHOST_ICC_UNROLL_PRAGMA
65 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll (4)") \
66 for (iter = val; iter < size; iter++)
69 #ifndef vhost_for_each_try_unroll
70 #define vhost_for_each_try_unroll(iter, val, num) \
71 for (iter = val; iter < num; iter++)
75 * Structure contains buffer address, length and descriptor index
76 * from vring to do scatter RX.
86 * A structure to hold some fields needed in zero copy code path,
87 * mainly for associating an mbuf with the right desc_idx.
90 struct rte_mbuf *mbuf;
95 TAILQ_ENTRY(zcopy_mbuf) next;
97 TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
100 * Structure contains the info for each batched memory copy.
102 struct batch_copy_elem {
110 * Structure that contains the info for batched dirty logging.
112 struct log_cache_entry {
117 struct vring_used_elem_packed {
125 * Structure contains variables relevant to RX/TX virtqueues.
127 struct vhost_virtqueue {
129 struct vring_desc *desc;
130 struct vring_packed_desc *desc_packed;
133 struct vring_avail *avail;
134 struct vring_packed_desc_event *driver_event;
137 struct vring_used *used;
138 struct vring_packed_desc_event *device_event;
142 uint16_t last_avail_idx;
143 uint16_t last_used_idx;
144 /* Last used index we notify to front end. */
145 uint16_t signalled_used;
146 bool signalled_used_valid;
147 #define VIRTIO_INVALID_EVENTFD (-1)
148 #define VIRTIO_UNINITIALIZED_EVENTFD (-2)
150 /* Backend value to determine if device should started/stopped */
154 rte_spinlock_t access_lock;
156 /* Used to notify the guest (trigger interrupt) */
158 /* Currently unused as polling mode is enabled */
161 /* Physical address of used ring, for logging */
162 uint64_t log_guest_addr;
164 /* inflight share memory info */
166 struct rte_vhost_inflight_info_split *inflight_split;
167 struct rte_vhost_inflight_info_packed *inflight_packed;
169 struct rte_vhost_resubmit_info *resubmit_inflight;
170 uint64_t global_counter;
174 uint16_t last_zmbuf_idx;
175 struct zcopy_mbuf *zmbufs;
176 struct zcopy_mbuf_list zmbuf_list;
179 struct vring_used_elem *shadow_used_split;
180 struct vring_used_elem_packed *shadow_used_packed;
182 uint16_t shadow_used_idx;
183 /* Record packed ring enqueue latest desc cache aligned index */
184 uint16_t shadow_aligned_idx;
185 /* Record packed ring first dequeue desc index */
186 uint16_t shadow_last_used_idx;
187 struct vhost_vring_addr ring_addrs;
189 struct batch_copy_elem *batch_copy_elems;
190 uint16_t batch_copy_nb_elems;
191 bool used_wrap_counter;
192 bool avail_wrap_counter;
194 struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
195 uint16_t log_cache_nb_elem;
197 rte_rwlock_t iotlb_lock;
198 rte_rwlock_t iotlb_pending_lock;
199 struct rte_mempool *iotlb_pool;
200 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
202 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
203 } __rte_cache_aligned;
205 /* Old kernels have no such macros defined */
206 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
207 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
210 #ifndef VIRTIO_NET_F_MQ
211 #define VIRTIO_NET_F_MQ 22
214 #define VHOST_MAX_VRING 0x100
215 #define VHOST_MAX_QUEUE_PAIRS 0x80
217 #ifndef VIRTIO_NET_F_MTU
218 #define VIRTIO_NET_F_MTU 3
221 #ifndef VIRTIO_F_ANY_LAYOUT
222 #define VIRTIO_F_ANY_LAYOUT 27
225 /* Declare IOMMU related bits for older kernels */
226 #ifndef VIRTIO_F_IOMMU_PLATFORM
228 #define VIRTIO_F_IOMMU_PLATFORM 33
230 struct vhost_iotlb_msg {
234 #define VHOST_ACCESS_RO 0x1
235 #define VHOST_ACCESS_WO 0x2
236 #define VHOST_ACCESS_RW 0x3
238 #define VHOST_IOTLB_MISS 1
239 #define VHOST_IOTLB_UPDATE 2
240 #define VHOST_IOTLB_INVALIDATE 3
241 #define VHOST_IOTLB_ACCESS_FAIL 4
245 #define VHOST_IOTLB_MSG 0x1
250 struct vhost_iotlb_msg iotlb;
257 * Define virtio 1.0 for older kernels
259 #ifndef VIRTIO_F_VERSION_1
260 #define VIRTIO_F_VERSION_1 32
263 /* Declare packed ring related bits for older kernels */
264 #ifndef VIRTIO_F_RING_PACKED
266 #define VIRTIO_F_RING_PACKED 34
268 struct vring_packed_desc {
275 struct vring_packed_desc_event {
282 * Declare below packed ring defines unconditionally
283 * as Kernel header might use different names.
285 #define VRING_DESC_F_AVAIL (1ULL << 7)
286 #define VRING_DESC_F_USED (1ULL << 15)
288 #define VRING_EVENT_F_ENABLE 0x0
289 #define VRING_EVENT_F_DISABLE 0x1
290 #define VRING_EVENT_F_DESC 0x2
293 * Available and used descs are in same order
295 #ifndef VIRTIO_F_IN_ORDER
296 #define VIRTIO_F_IN_ORDER 35
299 /* Features supported by this builtin vhost-user net driver. */
300 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
301 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
302 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
303 (1ULL << VIRTIO_NET_F_CTRL_RX) | \
304 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
305 (1ULL << VIRTIO_NET_F_MQ) | \
306 (1ULL << VIRTIO_F_VERSION_1) | \
307 (1ULL << VHOST_F_LOG_ALL) | \
308 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
309 (1ULL << VIRTIO_NET_F_GSO) | \
310 (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
311 (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
312 (1ULL << VIRTIO_NET_F_HOST_UFO) | \
313 (1ULL << VIRTIO_NET_F_HOST_ECN) | \
314 (1ULL << VIRTIO_NET_F_CSUM) | \
315 (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
316 (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
317 (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
318 (1ULL << VIRTIO_NET_F_GUEST_UFO) | \
319 (1ULL << VIRTIO_NET_F_GUEST_ECN) | \
320 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
321 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \
322 (1ULL << VIRTIO_NET_F_MTU) | \
323 (1ULL << VIRTIO_F_IN_ORDER) | \
324 (1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
325 (1ULL << VIRTIO_F_RING_PACKED))
329 uint64_t guest_phys_addr;
330 uint64_t host_phys_addr;
334 struct inflight_mem_info {
341 * Device structure contains all configuration information relating
345 /* Frontend (QEMU) memory and memory region information */
346 struct rte_vhost_memory *mem;
348 uint64_t protocol_features;
352 /* to tell if we need broadcast rarp packet */
353 int16_t broadcast_rarp;
355 int dequeue_zero_copy;
358 struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
359 struct inflight_mem_info *inflight_info;
360 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
361 char ifname[IF_NAME_SZ];
365 struct rte_ether_addr mac;
368 struct vhost_device_ops const *notify_ops;
370 uint32_t nr_guest_pages;
371 uint32_t max_guest_pages;
372 struct guest_page *guest_pages;
375 rte_spinlock_t slave_req_lock;
378 int postcopy_listening;
380 struct rte_vdpa_device *vdpa_dev;
382 /* context data for the external message handlers */
384 /* pre and post vhost user message handlers for the device */
385 struct rte_vhost_user_extern_ops extern_ops;
386 } __rte_cache_aligned;
388 static __rte_always_inline bool
389 vq_is_packed(struct virtio_net *dev)
391 return dev->features & (1ull << VIRTIO_F_RING_PACKED);
395 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
397 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
399 return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
400 wrap_counter != !!(flags & VRING_DESC_F_USED);
404 vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
406 vq->last_used_idx += num;
407 if (vq->last_used_idx >= vq->size) {
408 vq->used_wrap_counter ^= 1;
409 vq->last_used_idx -= vq->size;
414 vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
416 vq->last_avail_idx += num;
417 if (vq->last_avail_idx >= vq->size) {
418 vq->avail_wrap_counter ^= 1;
419 vq->last_avail_idx -= vq->size;
423 void __vhost_log_cache_write(struct virtio_net *dev,
424 struct vhost_virtqueue *vq,
425 uint64_t addr, uint64_t len);
426 void __vhost_log_cache_write_iova(struct virtio_net *dev,
427 struct vhost_virtqueue *vq,
428 uint64_t iova, uint64_t len);
429 void __vhost_log_cache_sync(struct virtio_net *dev,
430 struct vhost_virtqueue *vq);
431 void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
432 void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
433 uint64_t iova, uint64_t len);
435 static __rte_always_inline void
436 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
438 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
439 __vhost_log_write(dev, addr, len);
442 static __rte_always_inline void
443 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
445 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
446 __vhost_log_cache_sync(dev, vq);
449 static __rte_always_inline void
450 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
451 uint64_t addr, uint64_t len)
453 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
454 __vhost_log_cache_write(dev, vq, addr, len);
457 static __rte_always_inline void
458 vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
459 uint64_t offset, uint64_t len)
461 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
462 if (unlikely(vq->log_guest_addr == 0))
464 __vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,
469 static __rte_always_inline void
470 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
471 uint64_t offset, uint64_t len)
473 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
474 if (unlikely(vq->log_guest_addr == 0))
476 __vhost_log_write(dev, vq->log_guest_addr + offset, len);
480 static __rte_always_inline void
481 vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
482 uint64_t iova, uint64_t len)
484 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
487 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
488 __vhost_log_cache_write_iova(dev, vq, iova, len);
490 __vhost_log_cache_write(dev, vq, iova, len);
493 static __rte_always_inline void
494 vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
495 uint64_t iova, uint64_t len)
497 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
500 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
501 __vhost_log_write_iova(dev, vq, iova, len);
503 __vhost_log_write(dev, iova, len);
506 extern int vhost_config_log_level;
507 extern int vhost_data_log_level;
509 #define VHOST_LOG_CONFIG(level, fmt, args...) \
510 rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
511 "VHOST_CONFIG: " fmt, ##args)
513 #define VHOST_LOG_DATA(level, fmt, args...) \
514 (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
515 rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
516 "VHOST_DATA : " fmt, ##args) : \
519 #ifdef RTE_LIBRTE_VHOST_DEBUG
520 #define VHOST_MAX_PRINT_BUFF 6072
521 #define PRINT_PACKET(device, addr, size, header) do { \
522 char *pkt_addr = (char *)(addr); \
523 unsigned int index; \
524 char packet[VHOST_MAX_PRINT_BUFF]; \
527 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
529 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
530 for (index = 0; index < (size); index++) { \
531 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
532 "%02hhx ", pkt_addr[index]); \
534 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
536 VHOST_LOG_DATA(DEBUG, "%s", packet); \
539 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
542 #define MAX_VHOST_DEVICE 1024
543 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
545 #define VHOST_BINARY_SEARCH_THRESH 256
547 static __rte_always_inline int guest_page_addrcmp(const void *p1,
550 const struct guest_page *page1 = (const struct guest_page *)p1;
551 const struct guest_page *page2 = (const struct guest_page *)p2;
553 if (page1->guest_phys_addr > page2->guest_phys_addr)
555 if (page1->guest_phys_addr < page2->guest_phys_addr)
561 /* Convert guest physical address to host physical address */
562 static __rte_always_inline rte_iova_t
563 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
566 struct guest_page *page;
567 struct guest_page key;
569 if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
570 key.guest_phys_addr = gpa;
571 page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
572 sizeof(struct guest_page), guest_page_addrcmp);
574 if (gpa + size < page->guest_phys_addr + page->size)
575 return gpa - page->guest_phys_addr +
576 page->host_phys_addr;
579 for (i = 0; i < dev->nr_guest_pages; i++) {
580 page = &dev->guest_pages[i];
582 if (gpa >= page->guest_phys_addr &&
583 gpa + size < page->guest_phys_addr +
585 return gpa - page->guest_phys_addr +
586 page->host_phys_addr;
593 static __rte_always_inline uint64_t
594 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
596 struct rte_vhost_mem_region *r;
599 if (unlikely(!dev || !dev->mem))
602 for (i = 0; i < dev->mem->nregions; i++) {
603 r = &dev->mem->regions[i];
605 if (vva >= r->host_user_addr &&
606 vva + len < r->host_user_addr + r->size) {
607 return r->guest_phys_addr + vva - r->host_user_addr;
613 static __rte_always_inline struct virtio_net *
616 struct virtio_net *dev = vhost_devices[vid];
618 if (unlikely(!dev)) {
619 VHOST_LOG_CONFIG(ERR,
620 "(%d) device not found.\n", vid);
626 int vhost_new_device(void);
627 void cleanup_device(struct virtio_net *dev, int destroy);
628 void reset_device(struct virtio_net *dev);
629 void vhost_destroy_device(int);
630 void vhost_destroy_device_notify(struct virtio_net *dev);
632 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
633 void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
634 void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
636 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
638 void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
640 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
641 void vhost_enable_dequeue_zero_copy(int vid);
642 void vhost_set_builtin_virtio_net(int vid, bool enable);
643 void vhost_enable_extbuf(int vid);
644 void vhost_enable_linearbuf(int vid);
646 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
649 * Backend-specific cleanup.
651 * TODO: fix it; we have one backend now
653 void vhost_backend_cleanup(struct virtio_net *dev);
655 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
656 uint64_t iova, uint64_t *len, uint8_t perm);
657 void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
658 struct vhost_virtqueue *vq,
659 uint64_t desc_addr, uint64_t desc_len);
660 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
661 uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
663 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
665 static __rte_always_inline uint64_t
666 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
667 uint64_t iova, uint64_t *len, uint8_t perm)
669 if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
670 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
672 return __vhost_iova_to_vva(dev, vq, iova, len, perm);
675 #define vhost_avail_event(vr) \
676 (*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
677 #define vhost_used_event(vr) \
678 (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
681 * The following is used with VIRTIO_RING_F_EVENT_IDX.
682 * Assuming a given event_idx value from the other size, if we have
683 * just incremented index from old to new_idx, should we trigger an
686 static __rte_always_inline int
687 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
689 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
692 static __rte_always_inline void
693 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
695 /* Flush used->idx update before we read avail->flags. */
698 /* Don't kick guest if we don't reach index specified by guest. */
699 if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
700 uint16_t old = vq->signalled_used;
701 uint16_t new = vq->last_used_idx;
702 bool signalled_used_valid = vq->signalled_used_valid;
704 vq->signalled_used = new;
705 vq->signalled_used_valid = true;
707 VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
709 vhost_used_event(vq),
712 if ((vhost_need_event(vhost_used_event(vq), new, old) &&
713 (vq->callfd >= 0)) ||
714 unlikely(!signalled_used_valid)) {
715 eventfd_write(vq->callfd, (eventfd_t) 1);
716 if (dev->notify_ops->guest_notified)
717 dev->notify_ops->guest_notified(dev->vid);
720 /* Kick the guest if necessary. */
721 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
722 && (vq->callfd >= 0)) {
723 eventfd_write(vq->callfd, (eventfd_t)1);
724 if (dev->notify_ops->guest_notified)
725 dev->notify_ops->guest_notified(dev->vid);
730 static __rte_always_inline void
731 vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
733 uint16_t old, new, off, off_wrap;
734 bool signalled_used_valid, kick = false;
736 /* Flush used desc update. */
739 if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
740 if (vq->driver_event->flags !=
741 VRING_EVENT_F_DISABLE)
746 old = vq->signalled_used;
747 new = vq->last_used_idx;
748 vq->signalled_used = new;
749 signalled_used_valid = vq->signalled_used_valid;
750 vq->signalled_used_valid = true;
752 if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
753 if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
758 if (unlikely(!signalled_used_valid)) {
765 off_wrap = vq->driver_event->off_wrap;
766 off = off_wrap & ~(1 << 15);
771 if (vq->used_wrap_counter != off_wrap >> 15)
774 if (vhost_need_event(off, new, old))
778 eventfd_write(vq->callfd, (eventfd_t)1);
779 if (dev->notify_ops->guest_notified)
780 dev->notify_ops->guest_notified(dev->vid);
784 static __rte_always_inline void
785 free_ind_table(void *idesc)
790 static __rte_always_inline void
791 restore_mbuf(struct rte_mbuf *m)
793 uint32_t mbuf_size, priv_size;
796 priv_size = rte_pktmbuf_priv_size(m->pool);
797 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
798 /* start of buffer is after mbuf structure and priv data */
800 m->buf_addr = (char *)m + mbuf_size;
801 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
806 static __rte_always_inline bool
807 mbuf_is_consumed(struct rte_mbuf *m)
810 if (rte_mbuf_refcnt_read(m) > 1)
818 static __rte_always_inline void
819 put_zmbuf(struct zcopy_mbuf *zmbuf)
824 #endif /* _VHOST_NET_CDEV_H_ */