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"
25 #include "rte_vdpa_dev.h"
27 /* Used to indicate that the device is running on a data core */
28 #define VIRTIO_DEV_RUNNING 1
29 /* Used to indicate that the device is ready to operate */
30 #define VIRTIO_DEV_READY 2
31 /* Used to indicate that the built-in vhost net device backend is enabled */
32 #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
33 /* Used to indicate that the device has its own data path and configured */
34 #define VIRTIO_DEV_VDPA_CONFIGURED 8
36 /* Backend value set by guest. */
37 #define VIRTIO_DEV_STOPPED -1
39 #define BUF_VECTOR_MAX 256
41 #define VHOST_LOG_CACHE_NR 32
43 #define PACKED_DESC_ENQUEUE_USED_FLAG(w) \
44 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \
46 #define PACKED_DESC_DEQUEUE_USED_FLAG(w) \
47 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED) : 0x0)
48 #define PACKED_DESC_SINGLE_DEQUEUE_FLAG (VRING_DESC_F_NEXT | \
49 VRING_DESC_F_INDIRECT)
51 #define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \
52 sizeof(struct vring_packed_desc))
53 #define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
55 #ifdef VHOST_GCC_UNROLL_PRAGMA
56 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
57 for (iter = val; iter < size; iter++)
60 #ifdef VHOST_CLANG_UNROLL_PRAGMA
61 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
62 for (iter = val; iter < size; iter++)
65 #ifdef VHOST_ICC_UNROLL_PRAGMA
66 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll (4)") \
67 for (iter = val; iter < size; iter++)
70 #ifndef vhost_for_each_try_unroll
71 #define vhost_for_each_try_unroll(iter, val, num) \
72 for (iter = val; iter < num; iter++)
76 * Structure contains buffer address, length and descriptor index
77 * from vring to do scatter RX.
87 * A structure to hold some fields needed in zero copy code path,
88 * mainly for associating an mbuf with the right desc_idx.
91 struct rte_mbuf *mbuf;
96 TAILQ_ENTRY(zcopy_mbuf) next;
98 TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
101 * Structure contains the info for each batched memory copy.
103 struct batch_copy_elem {
111 * Structure that contains the info for batched dirty logging.
113 struct log_cache_entry {
118 struct vring_used_elem_packed {
126 * Structure contains variables relevant to RX/TX virtqueues.
128 struct vhost_virtqueue {
130 struct vring_desc *desc;
131 struct vring_packed_desc *desc_packed;
134 struct vring_avail *avail;
135 struct vring_packed_desc_event *driver_event;
138 struct vring_used *used;
139 struct vring_packed_desc_event *device_event;
143 uint16_t last_avail_idx;
144 uint16_t last_used_idx;
145 /* Last used index we notify to front end. */
146 uint16_t signalled_used;
147 bool signalled_used_valid;
148 #define VIRTIO_INVALID_EVENTFD (-1)
149 #define VIRTIO_UNINITIALIZED_EVENTFD (-2)
151 /* Backend value to determine if device should started/stopped */
156 rte_spinlock_t access_lock;
158 /* Used to notify the guest (trigger interrupt) */
160 /* Currently unused as polling mode is enabled */
163 /* Physical address of used ring, for logging */
164 uint64_t log_guest_addr;
166 /* inflight share memory info */
168 struct rte_vhost_inflight_info_split *inflight_split;
169 struct rte_vhost_inflight_info_packed *inflight_packed;
171 struct rte_vhost_resubmit_info *resubmit_inflight;
172 uint64_t global_counter;
176 uint16_t last_zmbuf_idx;
177 struct zcopy_mbuf *zmbufs;
178 struct zcopy_mbuf_list zmbuf_list;
181 struct vring_used_elem *shadow_used_split;
182 struct vring_used_elem_packed *shadow_used_packed;
184 uint16_t shadow_used_idx;
185 /* Record packed ring enqueue latest desc cache aligned index */
186 uint16_t shadow_aligned_idx;
187 /* Record packed ring first dequeue desc index */
188 uint16_t shadow_last_used_idx;
189 struct vhost_vring_addr ring_addrs;
191 struct batch_copy_elem *batch_copy_elems;
192 uint16_t batch_copy_nb_elems;
193 bool used_wrap_counter;
194 bool avail_wrap_counter;
196 struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
197 uint16_t log_cache_nb_elem;
199 rte_rwlock_t iotlb_lock;
200 rte_rwlock_t iotlb_pending_lock;
201 struct rte_mempool *iotlb_pool;
202 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
204 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
205 } __rte_cache_aligned;
207 /* Old kernels have no such macros defined */
208 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
209 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
212 #ifndef VIRTIO_NET_F_MQ
213 #define VIRTIO_NET_F_MQ 22
216 #define VHOST_MAX_VRING 0x100
217 #define VHOST_MAX_QUEUE_PAIRS 0x80
219 #ifndef VIRTIO_NET_F_MTU
220 #define VIRTIO_NET_F_MTU 3
223 #ifndef VIRTIO_F_ANY_LAYOUT
224 #define VIRTIO_F_ANY_LAYOUT 27
227 /* Declare IOMMU related bits for older kernels */
228 #ifndef VIRTIO_F_IOMMU_PLATFORM
230 #define VIRTIO_F_IOMMU_PLATFORM 33
232 struct vhost_iotlb_msg {
236 #define VHOST_ACCESS_RO 0x1
237 #define VHOST_ACCESS_WO 0x2
238 #define VHOST_ACCESS_RW 0x3
240 #define VHOST_IOTLB_MISS 1
241 #define VHOST_IOTLB_UPDATE 2
242 #define VHOST_IOTLB_INVALIDATE 3
243 #define VHOST_IOTLB_ACCESS_FAIL 4
247 #define VHOST_IOTLB_MSG 0x1
252 struct vhost_iotlb_msg iotlb;
259 * Define virtio 1.0 for older kernels
261 #ifndef VIRTIO_F_VERSION_1
262 #define VIRTIO_F_VERSION_1 32
265 /* Declare packed ring related bits for older kernels */
266 #ifndef VIRTIO_F_RING_PACKED
268 #define VIRTIO_F_RING_PACKED 34
270 struct vring_packed_desc {
277 struct vring_packed_desc_event {
284 * Declare below packed ring defines unconditionally
285 * as Kernel header might use different names.
287 #define VRING_DESC_F_AVAIL (1ULL << 7)
288 #define VRING_DESC_F_USED (1ULL << 15)
290 #define VRING_EVENT_F_ENABLE 0x0
291 #define VRING_EVENT_F_DISABLE 0x1
292 #define VRING_EVENT_F_DESC 0x2
295 * Available and used descs are in same order
297 #ifndef VIRTIO_F_IN_ORDER
298 #define VIRTIO_F_IN_ORDER 35
301 /* Features supported by this builtin vhost-user net driver. */
302 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
303 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
304 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
305 (1ULL << VIRTIO_NET_F_CTRL_RX) | \
306 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
307 (1ULL << VIRTIO_NET_F_MQ) | \
308 (1ULL << VIRTIO_F_VERSION_1) | \
309 (1ULL << VHOST_F_LOG_ALL) | \
310 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
311 (1ULL << VIRTIO_NET_F_GSO) | \
312 (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
313 (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
314 (1ULL << VIRTIO_NET_F_HOST_UFO) | \
315 (1ULL << VIRTIO_NET_F_HOST_ECN) | \
316 (1ULL << VIRTIO_NET_F_CSUM) | \
317 (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
318 (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
319 (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
320 (1ULL << VIRTIO_NET_F_GUEST_UFO) | \
321 (1ULL << VIRTIO_NET_F_GUEST_ECN) | \
322 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
323 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \
324 (1ULL << VIRTIO_NET_F_MTU) | \
325 (1ULL << VIRTIO_F_IN_ORDER) | \
326 (1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
327 (1ULL << VIRTIO_F_RING_PACKED))
331 uint64_t guest_phys_addr;
332 uint64_t host_phys_addr;
336 struct inflight_mem_info {
343 * Device structure contains all configuration information relating
347 /* Frontend (QEMU) memory and memory region information */
348 struct rte_vhost_memory *mem;
350 uint64_t protocol_features;
354 /* to tell if we need broadcast rarp packet */
355 int16_t broadcast_rarp;
357 int dequeue_zero_copy;
360 struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
361 struct inflight_mem_info *inflight_info;
362 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
363 char ifname[IF_NAME_SZ];
367 struct rte_ether_addr mac;
370 struct vhost_device_ops const *notify_ops;
372 uint32_t nr_guest_pages;
373 uint32_t max_guest_pages;
374 struct guest_page *guest_pages;
377 rte_spinlock_t slave_req_lock;
380 int postcopy_listening;
382 struct rte_vdpa_device *vdpa_dev;
384 /* context data for the external message handlers */
386 /* pre and post vhost user message handlers for the device */
387 struct rte_vhost_user_extern_ops extern_ops;
388 } __rte_cache_aligned;
390 static __rte_always_inline bool
391 vq_is_packed(struct virtio_net *dev)
393 return dev->features & (1ull << VIRTIO_F_RING_PACKED);
397 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
399 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
401 return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
402 wrap_counter != !!(flags & VRING_DESC_F_USED);
406 vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
408 vq->last_used_idx += num;
409 if (vq->last_used_idx >= vq->size) {
410 vq->used_wrap_counter ^= 1;
411 vq->last_used_idx -= vq->size;
416 vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
418 vq->last_avail_idx += num;
419 if (vq->last_avail_idx >= vq->size) {
420 vq->avail_wrap_counter ^= 1;
421 vq->last_avail_idx -= vq->size;
425 void __vhost_log_cache_write(struct virtio_net *dev,
426 struct vhost_virtqueue *vq,
427 uint64_t addr, uint64_t len);
428 void __vhost_log_cache_write_iova(struct virtio_net *dev,
429 struct vhost_virtqueue *vq,
430 uint64_t iova, uint64_t len);
431 void __vhost_log_cache_sync(struct virtio_net *dev,
432 struct vhost_virtqueue *vq);
433 void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
434 void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
435 uint64_t iova, uint64_t len);
437 static __rte_always_inline void
438 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
440 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
441 __vhost_log_write(dev, addr, len);
444 static __rte_always_inline void
445 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
447 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
448 __vhost_log_cache_sync(dev, vq);
451 static __rte_always_inline void
452 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
453 uint64_t addr, uint64_t len)
455 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
456 __vhost_log_cache_write(dev, vq, addr, len);
459 static __rte_always_inline void
460 vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
461 uint64_t offset, uint64_t len)
463 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
464 if (unlikely(vq->log_guest_addr == 0))
466 __vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,
471 static __rte_always_inline void
472 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
473 uint64_t offset, uint64_t len)
475 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
476 if (unlikely(vq->log_guest_addr == 0))
478 __vhost_log_write(dev, vq->log_guest_addr + offset, len);
482 static __rte_always_inline void
483 vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
484 uint64_t iova, uint64_t len)
486 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
489 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
490 __vhost_log_cache_write_iova(dev, vq, iova, len);
492 __vhost_log_cache_write(dev, vq, iova, len);
495 static __rte_always_inline void
496 vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
497 uint64_t iova, uint64_t len)
499 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
502 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
503 __vhost_log_write_iova(dev, vq, iova, len);
505 __vhost_log_write(dev, iova, len);
508 extern int vhost_config_log_level;
509 extern int vhost_data_log_level;
511 #define VHOST_LOG_CONFIG(level, fmt, args...) \
512 rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
513 "VHOST_CONFIG: " fmt, ##args)
515 #define VHOST_LOG_DATA(level, fmt, args...) \
516 (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
517 rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
518 "VHOST_DATA : " fmt, ##args) : \
521 #ifdef RTE_LIBRTE_VHOST_DEBUG
522 #define VHOST_MAX_PRINT_BUFF 6072
523 #define PRINT_PACKET(device, addr, size, header) do { \
524 char *pkt_addr = (char *)(addr); \
525 unsigned int index; \
526 char packet[VHOST_MAX_PRINT_BUFF]; \
529 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
531 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
532 for (index = 0; index < (size); index++) { \
533 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
534 "%02hhx ", pkt_addr[index]); \
536 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
538 VHOST_LOG_DATA(DEBUG, "%s", packet); \
541 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
544 #define MAX_VHOST_DEVICE 1024
545 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
547 #define VHOST_BINARY_SEARCH_THRESH 256
549 static __rte_always_inline int guest_page_addrcmp(const void *p1,
552 const struct guest_page *page1 = (const struct guest_page *)p1;
553 const struct guest_page *page2 = (const struct guest_page *)p2;
555 if (page1->guest_phys_addr > page2->guest_phys_addr)
557 if (page1->guest_phys_addr < page2->guest_phys_addr)
563 /* Convert guest physical address to host physical address */
564 static __rte_always_inline rte_iova_t
565 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
568 struct guest_page *page;
569 struct guest_page key;
571 if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
572 key.guest_phys_addr = gpa;
573 page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
574 sizeof(struct guest_page), guest_page_addrcmp);
576 if (gpa + size < page->guest_phys_addr + page->size)
577 return gpa - page->guest_phys_addr +
578 page->host_phys_addr;
581 for (i = 0; i < dev->nr_guest_pages; i++) {
582 page = &dev->guest_pages[i];
584 if (gpa >= page->guest_phys_addr &&
585 gpa + size < page->guest_phys_addr +
587 return gpa - page->guest_phys_addr +
588 page->host_phys_addr;
595 static __rte_always_inline uint64_t
596 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
598 struct rte_vhost_mem_region *r;
601 if (unlikely(!dev || !dev->mem))
604 for (i = 0; i < dev->mem->nregions; i++) {
605 r = &dev->mem->regions[i];
607 if (vva >= r->host_user_addr &&
608 vva + len < r->host_user_addr + r->size) {
609 return r->guest_phys_addr + vva - r->host_user_addr;
615 static __rte_always_inline struct virtio_net *
618 struct virtio_net *dev = vhost_devices[vid];
620 if (unlikely(!dev)) {
621 VHOST_LOG_CONFIG(ERR,
622 "(%d) device not found.\n", vid);
628 int vhost_new_device(void);
629 void cleanup_device(struct virtio_net *dev, int destroy);
630 void reset_device(struct virtio_net *dev);
631 void vhost_destroy_device(int);
632 void vhost_destroy_device_notify(struct virtio_net *dev);
634 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
635 void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
636 void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
638 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
640 void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
642 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
643 void vhost_enable_dequeue_zero_copy(int vid);
644 void vhost_set_builtin_virtio_net(int vid, bool enable);
645 void vhost_enable_extbuf(int vid);
646 void vhost_enable_linearbuf(int vid);
648 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
651 * Backend-specific cleanup.
653 * TODO: fix it; we have one backend now
655 void vhost_backend_cleanup(struct virtio_net *dev);
657 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
658 uint64_t iova, uint64_t *len, uint8_t perm);
659 void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
660 struct vhost_virtqueue *vq,
661 uint64_t desc_addr, uint64_t desc_len);
662 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
663 uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
665 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
667 static __rte_always_inline uint64_t
668 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
669 uint64_t iova, uint64_t *len, uint8_t perm)
671 if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
672 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
674 return __vhost_iova_to_vva(dev, vq, iova, len, perm);
677 #define vhost_avail_event(vr) \
678 (*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
679 #define vhost_used_event(vr) \
680 (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
683 * The following is used with VIRTIO_RING_F_EVENT_IDX.
684 * Assuming a given event_idx value from the other size, if we have
685 * just incremented index from old to new_idx, should we trigger an
688 static __rte_always_inline int
689 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
691 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
694 static __rte_always_inline void
695 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
697 /* Flush used->idx update before we read avail->flags. */
700 /* Don't kick guest if we don't reach index specified by guest. */
701 if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
702 uint16_t old = vq->signalled_used;
703 uint16_t new = vq->last_used_idx;
704 bool signalled_used_valid = vq->signalled_used_valid;
706 vq->signalled_used = new;
707 vq->signalled_used_valid = true;
709 VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
711 vhost_used_event(vq),
714 if ((vhost_need_event(vhost_used_event(vq), new, old) &&
715 (vq->callfd >= 0)) ||
716 unlikely(!signalled_used_valid)) {
717 eventfd_write(vq->callfd, (eventfd_t) 1);
718 if (dev->notify_ops->guest_notified)
719 dev->notify_ops->guest_notified(dev->vid);
722 /* Kick the guest if necessary. */
723 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
724 && (vq->callfd >= 0)) {
725 eventfd_write(vq->callfd, (eventfd_t)1);
726 if (dev->notify_ops->guest_notified)
727 dev->notify_ops->guest_notified(dev->vid);
732 static __rte_always_inline void
733 vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
735 uint16_t old, new, off, off_wrap;
736 bool signalled_used_valid, kick = false;
738 /* Flush used desc update. */
741 if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
742 if (vq->driver_event->flags !=
743 VRING_EVENT_F_DISABLE)
748 old = vq->signalled_used;
749 new = vq->last_used_idx;
750 vq->signalled_used = new;
751 signalled_used_valid = vq->signalled_used_valid;
752 vq->signalled_used_valid = true;
754 if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
755 if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
760 if (unlikely(!signalled_used_valid)) {
767 off_wrap = vq->driver_event->off_wrap;
768 off = off_wrap & ~(1 << 15);
773 if (vq->used_wrap_counter != off_wrap >> 15)
776 if (vhost_need_event(off, new, old))
780 eventfd_write(vq->callfd, (eventfd_t)1);
781 if (dev->notify_ops->guest_notified)
782 dev->notify_ops->guest_notified(dev->vid);
786 static __rte_always_inline void
787 free_ind_table(void *idesc)
792 static __rte_always_inline void
793 restore_mbuf(struct rte_mbuf *m)
795 uint32_t mbuf_size, priv_size;
798 priv_size = rte_pktmbuf_priv_size(m->pool);
799 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
800 /* start of buffer is after mbuf structure and priv data */
802 m->buf_addr = (char *)m + mbuf_size;
803 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
808 static __rte_always_inline bool
809 mbuf_is_consumed(struct rte_mbuf *m)
812 if (rte_mbuf_refcnt_read(m) > 1)
820 static __rte_always_inline void
821 put_zmbuf(struct zcopy_mbuf *zmbuf)
826 #endif /* _VHOST_NET_CDEV_H_ */