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;
381 * Device id to identify a specific backend device.
382 * It's set to -1 for the default software implementation.
386 /* context data for the external message handlers */
388 /* pre and post vhost user message handlers for the device */
389 struct rte_vhost_user_extern_ops extern_ops;
390 } __rte_cache_aligned;
392 static __rte_always_inline bool
393 vq_is_packed(struct virtio_net *dev)
395 return dev->features & (1ull << VIRTIO_F_RING_PACKED);
399 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
401 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
403 return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
404 wrap_counter != !!(flags & VRING_DESC_F_USED);
408 vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
410 vq->last_used_idx += num;
411 if (vq->last_used_idx >= vq->size) {
412 vq->used_wrap_counter ^= 1;
413 vq->last_used_idx -= vq->size;
418 vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
420 vq->last_avail_idx += num;
421 if (vq->last_avail_idx >= vq->size) {
422 vq->avail_wrap_counter ^= 1;
423 vq->last_avail_idx -= vq->size;
427 void __vhost_log_cache_write(struct virtio_net *dev,
428 struct vhost_virtqueue *vq,
429 uint64_t addr, uint64_t len);
430 void __vhost_log_cache_write_iova(struct virtio_net *dev,
431 struct vhost_virtqueue *vq,
432 uint64_t iova, uint64_t len);
433 void __vhost_log_cache_sync(struct virtio_net *dev,
434 struct vhost_virtqueue *vq);
435 void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
436 void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
437 uint64_t iova, uint64_t len);
439 static __rte_always_inline void
440 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
442 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
443 __vhost_log_write(dev, addr, len);
446 static __rte_always_inline void
447 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
449 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
450 __vhost_log_cache_sync(dev, vq);
453 static __rte_always_inline void
454 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
455 uint64_t addr, uint64_t len)
457 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
458 __vhost_log_cache_write(dev, vq, addr, len);
461 static __rte_always_inline void
462 vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
463 uint64_t offset, uint64_t len)
465 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
466 if (unlikely(vq->log_guest_addr == 0))
468 __vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,
473 static __rte_always_inline void
474 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
475 uint64_t offset, uint64_t len)
477 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
478 if (unlikely(vq->log_guest_addr == 0))
480 __vhost_log_write(dev, vq->log_guest_addr + offset, len);
484 static __rte_always_inline void
485 vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
486 uint64_t iova, uint64_t len)
488 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
491 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
492 __vhost_log_cache_write_iova(dev, vq, iova, len);
494 __vhost_log_cache_write(dev, vq, iova, len);
497 static __rte_always_inline void
498 vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
499 uint64_t iova, uint64_t len)
501 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
504 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
505 __vhost_log_write_iova(dev, vq, iova, len);
507 __vhost_log_write(dev, iova, len);
510 extern int vhost_config_log_level;
511 extern int vhost_data_log_level;
513 #define VHOST_LOG_CONFIG(level, fmt, args...) \
514 rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
515 "VHOST_CONFIG: " fmt, ##args)
517 #define VHOST_LOG_DATA(level, fmt, args...) \
518 (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
519 rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
520 "VHOST_DATA : " fmt, ##args) : \
523 #ifdef RTE_LIBRTE_VHOST_DEBUG
524 #define VHOST_MAX_PRINT_BUFF 6072
525 #define PRINT_PACKET(device, addr, size, header) do { \
526 char *pkt_addr = (char *)(addr); \
527 unsigned int index; \
528 char packet[VHOST_MAX_PRINT_BUFF]; \
531 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
533 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
534 for (index = 0; index < (size); index++) { \
535 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
536 "%02hhx ", pkt_addr[index]); \
538 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
540 VHOST_LOG_DATA(DEBUG, "%s", packet); \
543 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
546 #define MAX_VHOST_DEVICE 1024
547 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
549 #define VHOST_BINARY_SEARCH_THRESH 256
551 static __rte_always_inline int guest_page_addrcmp(const void *p1,
554 const struct guest_page *page1 = (const struct guest_page *)p1;
555 const struct guest_page *page2 = (const struct guest_page *)p2;
557 if (page1->guest_phys_addr > page2->guest_phys_addr)
559 if (page1->guest_phys_addr < page2->guest_phys_addr)
565 /* Convert guest physical address to host physical address */
566 static __rte_always_inline rte_iova_t
567 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
570 struct guest_page *page;
571 struct guest_page key;
573 if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
574 key.guest_phys_addr = gpa;
575 page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
576 sizeof(struct guest_page), guest_page_addrcmp);
578 if (gpa + size < page->guest_phys_addr + page->size)
579 return gpa - page->guest_phys_addr +
580 page->host_phys_addr;
583 for (i = 0; i < dev->nr_guest_pages; i++) {
584 page = &dev->guest_pages[i];
586 if (gpa >= page->guest_phys_addr &&
587 gpa + size < page->guest_phys_addr +
589 return gpa - page->guest_phys_addr +
590 page->host_phys_addr;
597 static __rte_always_inline uint64_t
598 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
600 struct rte_vhost_mem_region *r;
603 if (unlikely(!dev || !dev->mem))
606 for (i = 0; i < dev->mem->nregions; i++) {
607 r = &dev->mem->regions[i];
609 if (vva >= r->host_user_addr &&
610 vva + len < r->host_user_addr + r->size) {
611 return r->guest_phys_addr + vva - r->host_user_addr;
617 static __rte_always_inline struct virtio_net *
620 struct virtio_net *dev = vhost_devices[vid];
622 if (unlikely(!dev)) {
623 VHOST_LOG_CONFIG(ERR,
624 "(%d) device not found.\n", vid);
630 int vhost_new_device(void);
631 void cleanup_device(struct virtio_net *dev, int destroy);
632 void reset_device(struct virtio_net *dev);
633 void vhost_destroy_device(int);
634 void vhost_destroy_device_notify(struct virtio_net *dev);
636 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
637 void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
638 void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
640 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
642 void vhost_attach_vdpa_device(int vid, int did);
644 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
645 void vhost_enable_dequeue_zero_copy(int vid);
646 void vhost_set_builtin_virtio_net(int vid, bool enable);
647 void vhost_enable_extbuf(int vid);
648 void vhost_enable_linearbuf(int vid);
650 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
653 * Backend-specific cleanup.
655 * TODO: fix it; we have one backend now
657 void vhost_backend_cleanup(struct virtio_net *dev);
659 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
660 uint64_t iova, uint64_t *len, uint8_t perm);
661 void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
662 struct vhost_virtqueue *vq,
663 uint64_t desc_addr, uint64_t desc_len);
664 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
665 uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
667 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
669 static __rte_always_inline uint64_t
670 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
671 uint64_t iova, uint64_t *len, uint8_t perm)
673 if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
674 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
676 return __vhost_iova_to_vva(dev, vq, iova, len, perm);
679 #define vhost_avail_event(vr) \
680 (*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
681 #define vhost_used_event(vr) \
682 (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
685 * The following is used with VIRTIO_RING_F_EVENT_IDX.
686 * Assuming a given event_idx value from the other size, if we have
687 * just incremented index from old to new_idx, should we trigger an
690 static __rte_always_inline int
691 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
693 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
696 static __rte_always_inline void
697 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
699 /* Flush used->idx update before we read avail->flags. */
702 /* Don't kick guest if we don't reach index specified by guest. */
703 if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
704 uint16_t old = vq->signalled_used;
705 uint16_t new = vq->last_used_idx;
706 bool signalled_used_valid = vq->signalled_used_valid;
708 vq->signalled_used = new;
709 vq->signalled_used_valid = true;
711 VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
713 vhost_used_event(vq),
716 if ((vhost_need_event(vhost_used_event(vq), new, old) &&
717 (vq->callfd >= 0)) ||
718 unlikely(!signalled_used_valid)) {
719 eventfd_write(vq->callfd, (eventfd_t) 1);
720 if (dev->notify_ops->guest_notified)
721 dev->notify_ops->guest_notified(dev->vid);
724 /* Kick the guest if necessary. */
725 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
726 && (vq->callfd >= 0)) {
727 eventfd_write(vq->callfd, (eventfd_t)1);
728 if (dev->notify_ops->guest_notified)
729 dev->notify_ops->guest_notified(dev->vid);
734 static __rte_always_inline void
735 vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
737 uint16_t old, new, off, off_wrap;
738 bool signalled_used_valid, kick = false;
740 /* Flush used desc update. */
743 if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
744 if (vq->driver_event->flags !=
745 VRING_EVENT_F_DISABLE)
750 old = vq->signalled_used;
751 new = vq->last_used_idx;
752 vq->signalled_used = new;
753 signalled_used_valid = vq->signalled_used_valid;
754 vq->signalled_used_valid = true;
756 if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
757 if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
762 if (unlikely(!signalled_used_valid)) {
769 off_wrap = vq->driver_event->off_wrap;
770 off = off_wrap & ~(1 << 15);
775 if (vq->used_wrap_counter != off_wrap >> 15)
778 if (vhost_need_event(off, new, old))
782 eventfd_write(vq->callfd, (eventfd_t)1);
783 if (dev->notify_ops->guest_notified)
784 dev->notify_ops->guest_notified(dev->vid);
788 static __rte_always_inline void
789 free_ind_table(void *idesc)
794 static __rte_always_inline void
795 restore_mbuf(struct rte_mbuf *m)
797 uint32_t mbuf_size, priv_size;
800 priv_size = rte_pktmbuf_priv_size(m->pool);
801 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
802 /* start of buffer is after mbuf structure and priv data */
804 m->buf_addr = (char *)m + mbuf_size;
805 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
810 static __rte_always_inline bool
811 mbuf_is_consumed(struct rte_mbuf *m)
814 if (rte_mbuf_refcnt_read(m) > 1)
822 static __rte_always_inline void
823 put_zmbuf(struct zcopy_mbuf *zmbuf)
828 #endif /* _VHOST_NET_CDEV_H_ */