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 #define VHOST_MAX_VRING 0x100
208 #define VHOST_MAX_QUEUE_PAIRS 0x80
210 /* Declare IOMMU related bits for older kernels */
211 #ifndef VIRTIO_F_IOMMU_PLATFORM
213 #define VIRTIO_F_IOMMU_PLATFORM 33
215 struct vhost_iotlb_msg {
219 #define VHOST_ACCESS_RO 0x1
220 #define VHOST_ACCESS_WO 0x2
221 #define VHOST_ACCESS_RW 0x3
223 #define VHOST_IOTLB_MISS 1
224 #define VHOST_IOTLB_UPDATE 2
225 #define VHOST_IOTLB_INVALIDATE 3
226 #define VHOST_IOTLB_ACCESS_FAIL 4
230 #define VHOST_IOTLB_MSG 0x1
235 struct vhost_iotlb_msg iotlb;
242 * Define virtio 1.0 for older kernels
244 #ifndef VIRTIO_F_VERSION_1
245 #define VIRTIO_F_VERSION_1 32
248 /* Declare packed ring related bits for older kernels */
249 #ifndef VIRTIO_F_RING_PACKED
251 #define VIRTIO_F_RING_PACKED 34
253 struct vring_packed_desc {
260 struct vring_packed_desc_event {
267 * Declare below packed ring defines unconditionally
268 * as Kernel header might use different names.
270 #define VRING_DESC_F_AVAIL (1ULL << 7)
271 #define VRING_DESC_F_USED (1ULL << 15)
273 #define VRING_EVENT_F_ENABLE 0x0
274 #define VRING_EVENT_F_DISABLE 0x1
275 #define VRING_EVENT_F_DESC 0x2
278 * Available and used descs are in same order
280 #ifndef VIRTIO_F_IN_ORDER
281 #define VIRTIO_F_IN_ORDER 35
284 /* Features supported by this builtin vhost-user net driver. */
285 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
286 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
287 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
288 (1ULL << VIRTIO_NET_F_CTRL_RX) | \
289 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
290 (1ULL << VIRTIO_NET_F_MQ) | \
291 (1ULL << VIRTIO_F_VERSION_1) | \
292 (1ULL << VHOST_F_LOG_ALL) | \
293 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
294 (1ULL << VIRTIO_NET_F_GSO) | \
295 (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
296 (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
297 (1ULL << VIRTIO_NET_F_HOST_UFO) | \
298 (1ULL << VIRTIO_NET_F_HOST_ECN) | \
299 (1ULL << VIRTIO_NET_F_CSUM) | \
300 (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
301 (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
302 (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
303 (1ULL << VIRTIO_NET_F_GUEST_UFO) | \
304 (1ULL << VIRTIO_NET_F_GUEST_ECN) | \
305 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
306 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \
307 (1ULL << VIRTIO_NET_F_MTU) | \
308 (1ULL << VIRTIO_F_IN_ORDER) | \
309 (1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
310 (1ULL << VIRTIO_F_RING_PACKED))
314 uint64_t guest_phys_addr;
315 uint64_t host_phys_addr;
319 struct inflight_mem_info {
326 * Device structure contains all configuration information relating
330 /* Frontend (QEMU) memory and memory region information */
331 struct rte_vhost_memory *mem;
333 uint64_t protocol_features;
337 /* to tell if we need broadcast rarp packet */
338 int16_t broadcast_rarp;
340 int dequeue_zero_copy;
343 struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
344 struct inflight_mem_info *inflight_info;
345 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
346 char ifname[IF_NAME_SZ];
350 struct rte_ether_addr mac;
353 struct vhost_device_ops const *notify_ops;
355 uint32_t nr_guest_pages;
356 uint32_t max_guest_pages;
357 struct guest_page *guest_pages;
360 rte_spinlock_t slave_req_lock;
363 int postcopy_listening;
365 struct rte_vdpa_device *vdpa_dev;
367 /* context data for the external message handlers */
369 /* pre and post vhost user message handlers for the device */
370 struct rte_vhost_user_extern_ops extern_ops;
371 } __rte_cache_aligned;
373 static __rte_always_inline bool
374 vq_is_packed(struct virtio_net *dev)
376 return dev->features & (1ull << VIRTIO_F_RING_PACKED);
380 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
382 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
384 return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
385 wrap_counter != !!(flags & VRING_DESC_F_USED);
389 vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
391 vq->last_used_idx += num;
392 if (vq->last_used_idx >= vq->size) {
393 vq->used_wrap_counter ^= 1;
394 vq->last_used_idx -= vq->size;
399 vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
401 vq->last_avail_idx += num;
402 if (vq->last_avail_idx >= vq->size) {
403 vq->avail_wrap_counter ^= 1;
404 vq->last_avail_idx -= vq->size;
408 void __vhost_log_cache_write(struct virtio_net *dev,
409 struct vhost_virtqueue *vq,
410 uint64_t addr, uint64_t len);
411 void __vhost_log_cache_write_iova(struct virtio_net *dev,
412 struct vhost_virtqueue *vq,
413 uint64_t iova, uint64_t len);
414 void __vhost_log_cache_sync(struct virtio_net *dev,
415 struct vhost_virtqueue *vq);
416 void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
417 void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
418 uint64_t iova, uint64_t len);
420 static __rte_always_inline void
421 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
423 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
424 __vhost_log_write(dev, addr, len);
427 static __rte_always_inline void
428 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
430 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
431 __vhost_log_cache_sync(dev, vq);
434 static __rte_always_inline void
435 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
436 uint64_t addr, uint64_t len)
438 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
439 __vhost_log_cache_write(dev, vq, addr, len);
442 static __rte_always_inline void
443 vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
444 uint64_t offset, uint64_t len)
446 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
447 if (unlikely(vq->log_guest_addr == 0))
449 __vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,
454 static __rte_always_inline void
455 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
456 uint64_t offset, uint64_t len)
458 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
459 if (unlikely(vq->log_guest_addr == 0))
461 __vhost_log_write(dev, vq->log_guest_addr + offset, len);
465 static __rte_always_inline void
466 vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
467 uint64_t iova, uint64_t len)
469 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
472 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
473 __vhost_log_cache_write_iova(dev, vq, iova, len);
475 __vhost_log_cache_write(dev, vq, iova, len);
478 static __rte_always_inline void
479 vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
480 uint64_t iova, uint64_t len)
482 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
485 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
486 __vhost_log_write_iova(dev, vq, iova, len);
488 __vhost_log_write(dev, iova, len);
491 extern int vhost_config_log_level;
492 extern int vhost_data_log_level;
494 #define VHOST_LOG_CONFIG(level, fmt, args...) \
495 rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
496 "VHOST_CONFIG: " fmt, ##args)
498 #define VHOST_LOG_DATA(level, fmt, args...) \
499 (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
500 rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
501 "VHOST_DATA : " fmt, ##args) : \
504 #ifdef RTE_LIBRTE_VHOST_DEBUG
505 #define VHOST_MAX_PRINT_BUFF 6072
506 #define PRINT_PACKET(device, addr, size, header) do { \
507 char *pkt_addr = (char *)(addr); \
508 unsigned int index; \
509 char packet[VHOST_MAX_PRINT_BUFF]; \
512 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
514 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
515 for (index = 0; index < (size); index++) { \
516 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
517 "%02hhx ", pkt_addr[index]); \
519 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
521 VHOST_LOG_DATA(DEBUG, "%s", packet); \
524 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
527 #define MAX_VHOST_DEVICE 1024
528 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
530 #define VHOST_BINARY_SEARCH_THRESH 256
532 static __rte_always_inline int guest_page_addrcmp(const void *p1,
535 const struct guest_page *page1 = (const struct guest_page *)p1;
536 const struct guest_page *page2 = (const struct guest_page *)p2;
538 if (page1->guest_phys_addr > page2->guest_phys_addr)
540 if (page1->guest_phys_addr < page2->guest_phys_addr)
546 /* Convert guest physical address to host physical address */
547 static __rte_always_inline rte_iova_t
548 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
551 struct guest_page *page;
552 struct guest_page key;
554 if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
555 key.guest_phys_addr = gpa;
556 page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
557 sizeof(struct guest_page), guest_page_addrcmp);
559 if (gpa + size < page->guest_phys_addr + page->size)
560 return gpa - page->guest_phys_addr +
561 page->host_phys_addr;
564 for (i = 0; i < dev->nr_guest_pages; i++) {
565 page = &dev->guest_pages[i];
567 if (gpa >= page->guest_phys_addr &&
568 gpa + size < page->guest_phys_addr +
570 return gpa - page->guest_phys_addr +
571 page->host_phys_addr;
578 static __rte_always_inline uint64_t
579 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
581 struct rte_vhost_mem_region *r;
584 if (unlikely(!dev || !dev->mem))
587 for (i = 0; i < dev->mem->nregions; i++) {
588 r = &dev->mem->regions[i];
590 if (vva >= r->host_user_addr &&
591 vva + len < r->host_user_addr + r->size) {
592 return r->guest_phys_addr + vva - r->host_user_addr;
598 static __rte_always_inline struct virtio_net *
601 struct virtio_net *dev = vhost_devices[vid];
603 if (unlikely(!dev)) {
604 VHOST_LOG_CONFIG(ERR,
605 "(%d) device not found.\n", vid);
611 int vhost_new_device(void);
612 void cleanup_device(struct virtio_net *dev, int destroy);
613 void reset_device(struct virtio_net *dev);
614 void vhost_destroy_device(int);
615 void vhost_destroy_device_notify(struct virtio_net *dev);
617 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
618 void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
619 void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
621 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
623 void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
625 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
626 void vhost_enable_dequeue_zero_copy(int vid);
627 void vhost_set_builtin_virtio_net(int vid, bool enable);
628 void vhost_enable_extbuf(int vid);
629 void vhost_enable_linearbuf(int vid);
631 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
634 * Backend-specific cleanup.
636 * TODO: fix it; we have one backend now
638 void vhost_backend_cleanup(struct virtio_net *dev);
640 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
641 uint64_t iova, uint64_t *len, uint8_t perm);
642 void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
643 struct vhost_virtqueue *vq,
644 uint64_t desc_addr, uint64_t desc_len);
645 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
646 uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
648 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
650 static __rte_always_inline uint64_t
651 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
652 uint64_t iova, uint64_t *len, uint8_t perm)
654 if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
655 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
657 return __vhost_iova_to_vva(dev, vq, iova, len, perm);
660 #define vhost_avail_event(vr) \
661 (*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
662 #define vhost_used_event(vr) \
663 (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
666 * The following is used with VIRTIO_RING_F_EVENT_IDX.
667 * Assuming a given event_idx value from the other size, if we have
668 * just incremented index from old to new_idx, should we trigger an
671 static __rte_always_inline int
672 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
674 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
677 static __rte_always_inline void
678 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
680 /* Flush used->idx update before we read avail->flags. */
683 /* Don't kick guest if we don't reach index specified by guest. */
684 if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
685 uint16_t old = vq->signalled_used;
686 uint16_t new = vq->last_used_idx;
687 bool signalled_used_valid = vq->signalled_used_valid;
689 vq->signalled_used = new;
690 vq->signalled_used_valid = true;
692 VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
694 vhost_used_event(vq),
697 if ((vhost_need_event(vhost_used_event(vq), new, old) &&
698 (vq->callfd >= 0)) ||
699 unlikely(!signalled_used_valid)) {
700 eventfd_write(vq->callfd, (eventfd_t) 1);
701 if (dev->notify_ops->guest_notified)
702 dev->notify_ops->guest_notified(dev->vid);
705 /* Kick the guest if necessary. */
706 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
707 && (vq->callfd >= 0)) {
708 eventfd_write(vq->callfd, (eventfd_t)1);
709 if (dev->notify_ops->guest_notified)
710 dev->notify_ops->guest_notified(dev->vid);
715 static __rte_always_inline void
716 vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
718 uint16_t old, new, off, off_wrap;
719 bool signalled_used_valid, kick = false;
721 /* Flush used desc update. */
724 if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
725 if (vq->driver_event->flags !=
726 VRING_EVENT_F_DISABLE)
731 old = vq->signalled_used;
732 new = vq->last_used_idx;
733 vq->signalled_used = new;
734 signalled_used_valid = vq->signalled_used_valid;
735 vq->signalled_used_valid = true;
737 if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
738 if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
743 if (unlikely(!signalled_used_valid)) {
750 off_wrap = vq->driver_event->off_wrap;
751 off = off_wrap & ~(1 << 15);
756 if (vq->used_wrap_counter != off_wrap >> 15)
759 if (vhost_need_event(off, new, old))
763 eventfd_write(vq->callfd, (eventfd_t)1);
764 if (dev->notify_ops->guest_notified)
765 dev->notify_ops->guest_notified(dev->vid);
769 static __rte_always_inline void
770 free_ind_table(void *idesc)
775 static __rte_always_inline void
776 restore_mbuf(struct rte_mbuf *m)
778 uint32_t mbuf_size, priv_size;
781 priv_size = rte_pktmbuf_priv_size(m->pool);
782 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
783 /* start of buffer is after mbuf structure and priv data */
785 m->buf_addr = (char *)m + mbuf_size;
786 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
791 static __rte_always_inline bool
792 mbuf_is_consumed(struct rte_mbuf *m)
795 if (rte_mbuf_refcnt_read(m) > 1)
803 static __rte_always_inline void
804 put_zmbuf(struct zcopy_mbuf *zmbuf)
809 #endif /* _VHOST_NET_CDEV_H_ */