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 #include "rte_vhost_async.h"
29 /* Used to indicate that the device is running on a data core */
30 #define VIRTIO_DEV_RUNNING 1
31 /* Used to indicate that the device is ready to operate */
32 #define VIRTIO_DEV_READY 2
33 /* Used to indicate that the built-in vhost net device backend is enabled */
34 #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
35 /* Used to indicate that the device has its own data path and configured */
36 #define VIRTIO_DEV_VDPA_CONFIGURED 8
38 /* Backend value set by guest. */
39 #define VIRTIO_DEV_STOPPED -1
41 #define BUF_VECTOR_MAX 256
43 #define VHOST_LOG_CACHE_NR 32
45 #define MAX_PKT_BURST 32
47 #define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST * 2)
48 #define VHOST_MAX_ASYNC_VEC (BUF_VECTOR_MAX * 2)
50 #define PACKED_DESC_ENQUEUE_USED_FLAG(w) \
51 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \
53 #define PACKED_DESC_DEQUEUE_USED_FLAG(w) \
54 ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED) : 0x0)
55 #define PACKED_DESC_SINGLE_DEQUEUE_FLAG (VRING_DESC_F_NEXT | \
56 VRING_DESC_F_INDIRECT)
58 #define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \
59 sizeof(struct vring_packed_desc))
60 #define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1)
62 #ifdef VHOST_GCC_UNROLL_PRAGMA
63 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("GCC unroll 4") \
64 for (iter = val; iter < size; iter++)
67 #ifdef VHOST_CLANG_UNROLL_PRAGMA
68 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll 4") \
69 for (iter = val; iter < size; iter++)
72 #ifdef VHOST_ICC_UNROLL_PRAGMA
73 #define vhost_for_each_try_unroll(iter, val, size) _Pragma("unroll (4)") \
74 for (iter = val; iter < size; iter++)
77 #ifndef vhost_for_each_try_unroll
78 #define vhost_for_each_try_unroll(iter, val, num) \
79 for (iter = val; iter < num; iter++)
83 * Structure contains buffer address, length and descriptor index
84 * from vring to do scatter RX.
94 * A structure to hold some fields needed in zero copy code path,
95 * mainly for associating an mbuf with the right desc_idx.
98 struct rte_mbuf *mbuf;
103 TAILQ_ENTRY(zcopy_mbuf) next;
105 TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
108 * Structure contains the info for each batched memory copy.
110 struct batch_copy_elem {
118 * Structure that contains the info for batched dirty logging.
120 struct log_cache_entry {
125 struct vring_used_elem_packed {
133 * Structure contains variables relevant to RX/TX virtqueues.
135 struct vhost_virtqueue {
137 struct vring_desc *desc;
138 struct vring_packed_desc *desc_packed;
141 struct vring_avail *avail;
142 struct vring_packed_desc_event *driver_event;
145 struct vring_used *used;
146 struct vring_packed_desc_event *device_event;
150 uint16_t last_avail_idx;
151 uint16_t last_used_idx;
152 /* Last used index we notify to front end. */
153 uint16_t signalled_used;
154 bool signalled_used_valid;
155 #define VIRTIO_INVALID_EVENTFD (-1)
156 #define VIRTIO_UNINITIALIZED_EVENTFD (-2)
158 /* Backend value to determine if device should started/stopped */
163 rte_spinlock_t access_lock;
165 /* Used to notify the guest (trigger interrupt) */
167 /* Currently unused as polling mode is enabled */
170 /* Physical address of used ring, for logging */
171 uint64_t log_guest_addr;
173 /* inflight share memory info */
175 struct rte_vhost_inflight_info_split *inflight_split;
176 struct rte_vhost_inflight_info_packed *inflight_packed;
178 struct rte_vhost_resubmit_info *resubmit_inflight;
179 uint64_t global_counter;
183 uint16_t last_zmbuf_idx;
184 struct zcopy_mbuf *zmbufs;
185 struct zcopy_mbuf_list zmbuf_list;
188 struct vring_used_elem *shadow_used_split;
189 struct vring_used_elem_packed *shadow_used_packed;
191 uint16_t shadow_used_idx;
192 /* Record packed ring enqueue latest desc cache aligned index */
193 uint16_t shadow_aligned_idx;
194 /* Record packed ring first dequeue desc index */
195 uint16_t shadow_last_used_idx;
196 struct vhost_vring_addr ring_addrs;
198 struct batch_copy_elem *batch_copy_elems;
199 uint16_t batch_copy_nb_elems;
200 bool used_wrap_counter;
201 bool avail_wrap_counter;
203 struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
204 uint16_t log_cache_nb_elem;
206 rte_rwlock_t iotlb_lock;
207 rte_rwlock_t iotlb_pending_lock;
208 struct rte_mempool *iotlb_pool;
209 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
211 TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
213 /* operation callbacks for async dma */
214 struct rte_vhost_async_channel_ops async_ops;
216 struct rte_vhost_iov_iter it_pool[VHOST_MAX_ASYNC_IT];
217 struct iovec vec_pool[VHOST_MAX_ASYNC_VEC];
219 /* async data transfer status */
220 uintptr_t **async_pkts_pending;
221 #define ASYNC_PENDING_INFO_N_MSK 0xFFFF
222 #define ASYNC_PENDING_INFO_N_SFT 16
223 uint64_t *async_pending_info;
224 uint16_t async_pkts_idx;
225 uint16_t async_pkts_inflight_n;
227 /* vq async features */
229 bool async_registered;
230 uint16_t async_threshold;
231 } __rte_cache_aligned;
233 #define VHOST_MAX_VRING 0x100
234 #define VHOST_MAX_QUEUE_PAIRS 0x80
236 /* Declare IOMMU related bits for older kernels */
237 #ifndef VIRTIO_F_IOMMU_PLATFORM
239 #define VIRTIO_F_IOMMU_PLATFORM 33
241 struct vhost_iotlb_msg {
245 #define VHOST_ACCESS_RO 0x1
246 #define VHOST_ACCESS_WO 0x2
247 #define VHOST_ACCESS_RW 0x3
249 #define VHOST_IOTLB_MISS 1
250 #define VHOST_IOTLB_UPDATE 2
251 #define VHOST_IOTLB_INVALIDATE 3
252 #define VHOST_IOTLB_ACCESS_FAIL 4
256 #define VHOST_IOTLB_MSG 0x1
261 struct vhost_iotlb_msg iotlb;
268 * Define virtio 1.0 for older kernels
270 #ifndef VIRTIO_F_VERSION_1
271 #define VIRTIO_F_VERSION_1 32
274 /* Declare packed ring related bits for older kernels */
275 #ifndef VIRTIO_F_RING_PACKED
277 #define VIRTIO_F_RING_PACKED 34
279 struct vring_packed_desc {
286 struct vring_packed_desc_event {
293 * Declare below packed ring defines unconditionally
294 * as Kernel header might use different names.
296 #define VRING_DESC_F_AVAIL (1ULL << 7)
297 #define VRING_DESC_F_USED (1ULL << 15)
299 #define VRING_EVENT_F_ENABLE 0x0
300 #define VRING_EVENT_F_DISABLE 0x1
301 #define VRING_EVENT_F_DESC 0x2
304 * Available and used descs are in same order
306 #ifndef VIRTIO_F_IN_ORDER
307 #define VIRTIO_F_IN_ORDER 35
310 /* Features supported by this builtin vhost-user net driver. */
311 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
312 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
313 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
314 (1ULL << VIRTIO_NET_F_CTRL_RX) | \
315 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
316 (1ULL << VIRTIO_NET_F_MQ) | \
317 (1ULL << VIRTIO_F_VERSION_1) | \
318 (1ULL << VHOST_F_LOG_ALL) | \
319 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
320 (1ULL << VIRTIO_NET_F_GSO) | \
321 (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
322 (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
323 (1ULL << VIRTIO_NET_F_HOST_UFO) | \
324 (1ULL << VIRTIO_NET_F_HOST_ECN) | \
325 (1ULL << VIRTIO_NET_F_CSUM) | \
326 (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
327 (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
328 (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
329 (1ULL << VIRTIO_NET_F_GUEST_UFO) | \
330 (1ULL << VIRTIO_NET_F_GUEST_ECN) | \
331 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
332 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \
333 (1ULL << VIRTIO_NET_F_MTU) | \
334 (1ULL << VIRTIO_F_IN_ORDER) | \
335 (1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
336 (1ULL << VIRTIO_F_RING_PACKED))
340 uint64_t guest_phys_addr;
341 uint64_t host_phys_addr;
345 struct inflight_mem_info {
352 * Device structure contains all configuration information relating
356 /* Frontend (QEMU) memory and memory region information */
357 struct rte_vhost_memory *mem;
359 uint64_t protocol_features;
363 /* to tell if we need broadcast rarp packet */
364 int16_t broadcast_rarp;
366 int dequeue_zero_copy;
370 struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
371 struct inflight_mem_info *inflight_info;
372 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
373 char ifname[IF_NAME_SZ];
377 struct rte_ether_addr mac;
380 struct vhost_device_ops const *notify_ops;
382 uint32_t nr_guest_pages;
383 uint32_t max_guest_pages;
384 struct guest_page *guest_pages;
387 rte_spinlock_t slave_req_lock;
390 int postcopy_listening;
392 struct rte_vdpa_device *vdpa_dev;
394 /* context data for the external message handlers */
396 /* pre and post vhost user message handlers for the device */
397 struct rte_vhost_user_extern_ops extern_ops;
398 } __rte_cache_aligned;
400 static __rte_always_inline bool
401 vq_is_packed(struct virtio_net *dev)
403 return dev->features & (1ull << VIRTIO_F_RING_PACKED);
407 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
409 uint16_t flags = __atomic_load_n(&desc->flags, __ATOMIC_ACQUIRE);
411 return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) &&
412 wrap_counter != !!(flags & VRING_DESC_F_USED);
416 vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num)
418 vq->last_used_idx += num;
419 if (vq->last_used_idx >= vq->size) {
420 vq->used_wrap_counter ^= 1;
421 vq->last_used_idx -= vq->size;
426 vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)
428 vq->last_avail_idx += num;
429 if (vq->last_avail_idx >= vq->size) {
430 vq->avail_wrap_counter ^= 1;
431 vq->last_avail_idx -= vq->size;
435 void __vhost_log_cache_write(struct virtio_net *dev,
436 struct vhost_virtqueue *vq,
437 uint64_t addr, uint64_t len);
438 void __vhost_log_cache_write_iova(struct virtio_net *dev,
439 struct vhost_virtqueue *vq,
440 uint64_t iova, uint64_t len);
441 void __vhost_log_cache_sync(struct virtio_net *dev,
442 struct vhost_virtqueue *vq);
443 void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);
444 void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
445 uint64_t iova, uint64_t len);
447 static __rte_always_inline void
448 vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)
450 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
451 __vhost_log_write(dev, addr, len);
454 static __rte_always_inline void
455 vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq)
457 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
458 __vhost_log_cache_sync(dev, vq);
461 static __rte_always_inline void
462 vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq,
463 uint64_t addr, uint64_t len)
465 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL)))
466 __vhost_log_cache_write(dev, vq, addr, len);
469 static __rte_always_inline void
470 vhost_log_cache_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_cache_write(dev, vq, vq->log_guest_addr + offset,
481 static __rte_always_inline void
482 vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
483 uint64_t offset, uint64_t len)
485 if (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {
486 if (unlikely(vq->log_guest_addr == 0))
488 __vhost_log_write(dev, vq->log_guest_addr + offset, len);
492 static __rte_always_inline void
493 vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
494 uint64_t iova, uint64_t len)
496 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
499 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
500 __vhost_log_cache_write_iova(dev, vq, iova, len);
502 __vhost_log_cache_write(dev, vq, iova, len);
505 static __rte_always_inline void
506 vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
507 uint64_t iova, uint64_t len)
509 if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))
512 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
513 __vhost_log_write_iova(dev, vq, iova, len);
515 __vhost_log_write(dev, iova, len);
518 extern int vhost_config_log_level;
519 extern int vhost_data_log_level;
521 #define VHOST_LOG_CONFIG(level, fmt, args...) \
522 rte_log(RTE_LOG_ ## level, vhost_config_log_level, \
523 "VHOST_CONFIG: " fmt, ##args)
525 #define VHOST_LOG_DATA(level, fmt, args...) \
526 (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ? \
527 rte_log(RTE_LOG_ ## level, vhost_data_log_level, \
528 "VHOST_DATA : " fmt, ##args) : \
531 #ifdef RTE_LIBRTE_VHOST_DEBUG
532 #define VHOST_MAX_PRINT_BUFF 6072
533 #define PRINT_PACKET(device, addr, size, header) do { \
534 char *pkt_addr = (char *)(addr); \
535 unsigned int index; \
536 char packet[VHOST_MAX_PRINT_BUFF]; \
539 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
541 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
542 for (index = 0; index < (size); index++) { \
543 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
544 "%02hhx ", pkt_addr[index]); \
546 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
548 VHOST_LOG_DATA(DEBUG, "%s", packet); \
551 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
554 #define MAX_VHOST_DEVICE 1024
555 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
557 #define VHOST_BINARY_SEARCH_THRESH 256
559 static __rte_always_inline int guest_page_addrcmp(const void *p1,
562 const struct guest_page *page1 = (const struct guest_page *)p1;
563 const struct guest_page *page2 = (const struct guest_page *)p2;
565 if (page1->guest_phys_addr > page2->guest_phys_addr)
567 if (page1->guest_phys_addr < page2->guest_phys_addr)
573 /* Convert guest physical address to host physical address */
574 static __rte_always_inline rte_iova_t
575 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
578 struct guest_page *page;
579 struct guest_page key;
581 if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
582 key.guest_phys_addr = gpa;
583 page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
584 sizeof(struct guest_page), guest_page_addrcmp);
586 if (gpa + size < page->guest_phys_addr + page->size)
587 return gpa - page->guest_phys_addr +
588 page->host_phys_addr;
591 for (i = 0; i < dev->nr_guest_pages; i++) {
592 page = &dev->guest_pages[i];
594 if (gpa >= page->guest_phys_addr &&
595 gpa + size < page->guest_phys_addr +
597 return gpa - page->guest_phys_addr +
598 page->host_phys_addr;
605 static __rte_always_inline uint64_t
606 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
608 struct rte_vhost_mem_region *r;
611 if (unlikely(!dev || !dev->mem))
614 for (i = 0; i < dev->mem->nregions; i++) {
615 r = &dev->mem->regions[i];
617 if (vva >= r->host_user_addr &&
618 vva + len < r->host_user_addr + r->size) {
619 return r->guest_phys_addr + vva - r->host_user_addr;
625 static __rte_always_inline struct virtio_net *
628 struct virtio_net *dev = vhost_devices[vid];
630 if (unlikely(!dev)) {
631 VHOST_LOG_CONFIG(ERR,
632 "(%d) device not found.\n", vid);
638 int vhost_new_device(void);
639 void cleanup_device(struct virtio_net *dev, int destroy);
640 void reset_device(struct virtio_net *dev);
641 void vhost_destroy_device(int);
642 void vhost_destroy_device_notify(struct virtio_net *dev);
644 void cleanup_vq(struct vhost_virtqueue *vq, int destroy);
645 void cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq);
646 void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);
648 int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
650 void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
652 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
653 void vhost_enable_dequeue_zero_copy(int vid);
654 void vhost_set_builtin_virtio_net(int vid, bool enable);
655 void vhost_enable_extbuf(int vid);
656 void vhost_enable_linearbuf(int vid);
658 struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
661 * Backend-specific cleanup.
663 * TODO: fix it; we have one backend now
665 void vhost_backend_cleanup(struct virtio_net *dev);
667 uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
668 uint64_t iova, uint64_t *len, uint8_t perm);
669 void *vhost_alloc_copy_ind_table(struct virtio_net *dev,
670 struct vhost_virtqueue *vq,
671 uint64_t desc_addr, uint64_t desc_len);
672 int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);
673 uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,
675 void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);
677 static __rte_always_inline uint64_t
678 vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
679 uint64_t iova, uint64_t *len, uint8_t perm)
681 if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
682 return rte_vhost_va_from_guest_pa(dev->mem, iova, len);
684 return __vhost_iova_to_vva(dev, vq, iova, len, perm);
687 #define vhost_avail_event(vr) \
688 (*(volatile uint16_t*)&(vr)->used->ring[(vr)->size])
689 #define vhost_used_event(vr) \
690 (*(volatile uint16_t*)&(vr)->avail->ring[(vr)->size])
693 * The following is used with VIRTIO_RING_F_EVENT_IDX.
694 * Assuming a given event_idx value from the other size, if we have
695 * just incremented index from old to new_idx, should we trigger an
698 static __rte_always_inline int
699 vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
701 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
704 static __rte_always_inline void
705 vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
707 /* Flush used->idx update before we read avail->flags. */
710 /* Don't kick guest if we don't reach index specified by guest. */
711 if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
712 uint16_t old = vq->signalled_used;
713 uint16_t new = vq->async_pkts_inflight_n ?
714 vq->used->idx:vq->last_used_idx;
715 bool signalled_used_valid = vq->signalled_used_valid;
717 vq->signalled_used = new;
718 vq->signalled_used_valid = true;
720 VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
722 vhost_used_event(vq),
725 if ((vhost_need_event(vhost_used_event(vq), new, old) &&
726 (vq->callfd >= 0)) ||
727 unlikely(!signalled_used_valid)) {
728 eventfd_write(vq->callfd, (eventfd_t) 1);
729 if (dev->notify_ops->guest_notified)
730 dev->notify_ops->guest_notified(dev->vid);
733 /* Kick the guest if necessary. */
734 if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
735 && (vq->callfd >= 0)) {
736 eventfd_write(vq->callfd, (eventfd_t)1);
737 if (dev->notify_ops->guest_notified)
738 dev->notify_ops->guest_notified(dev->vid);
743 static __rte_always_inline void
744 vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
746 uint16_t old, new, off, off_wrap;
747 bool signalled_used_valid, kick = false;
749 /* Flush used desc update. */
752 if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
753 if (vq->driver_event->flags !=
754 VRING_EVENT_F_DISABLE)
759 old = vq->signalled_used;
760 new = vq->last_used_idx;
761 vq->signalled_used = new;
762 signalled_used_valid = vq->signalled_used_valid;
763 vq->signalled_used_valid = true;
765 if (vq->driver_event->flags != VRING_EVENT_F_DESC) {
766 if (vq->driver_event->flags != VRING_EVENT_F_DISABLE)
771 if (unlikely(!signalled_used_valid)) {
778 off_wrap = vq->driver_event->off_wrap;
779 off = off_wrap & ~(1 << 15);
784 if (vq->used_wrap_counter != off_wrap >> 15)
787 if (vhost_need_event(off, new, old))
791 eventfd_write(vq->callfd, (eventfd_t)1);
792 if (dev->notify_ops->guest_notified)
793 dev->notify_ops->guest_notified(dev->vid);
797 static __rte_always_inline void
798 free_ind_table(void *idesc)
803 static __rte_always_inline void
804 restore_mbuf(struct rte_mbuf *m)
806 uint32_t mbuf_size, priv_size;
809 priv_size = rte_pktmbuf_priv_size(m->pool);
810 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
811 /* start of buffer is after mbuf structure and priv data */
813 m->buf_addr = (char *)m + mbuf_size;
814 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
819 static __rte_always_inline bool
820 mbuf_is_consumed(struct rte_mbuf *m)
823 if (rte_mbuf_refcnt_read(m) > 1)
831 static __rte_always_inline void
832 put_zmbuf(struct zcopy_mbuf *zmbuf)
837 #endif /* _VHOST_NET_CDEV_H_ */