1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
7 #include <linux/virtio_net.h>
10 #include <rte_memcpy.h>
11 #include <rte_ether.h>
13 #include <rte_vhost.h>
18 #include <rte_spinlock.h>
19 #include <rte_malloc.h>
24 #define MAX_PKT_BURST 32
26 #define MAX_BATCH_LEN 256
28 static __rte_always_inline bool
29 rxvq_is_mergeable(struct virtio_net *dev)
31 return dev->features & (1ULL << VIRTIO_NET_F_MRG_RXBUF);
35 is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)
37 return (is_tx ^ (idx & 1)) == 0 && idx < nr_vring;
40 static __rte_always_inline void *
41 alloc_copy_ind_table(struct virtio_net *dev, struct vhost_virtqueue *vq,
42 uint64_t desc_addr, uint64_t desc_len)
46 uint64_t len, remain = desc_len;
48 idesc = rte_malloc(__func__, desc_len, 0);
52 dst = (uint64_t)(uintptr_t)idesc;
56 src = vhost_iova_to_vva(dev, vq, desc_addr, &len,
58 if (unlikely(!src || !len)) {
63 rte_memcpy((void *)(uintptr_t)dst, (void *)(uintptr_t)src, len);
73 static __rte_always_inline void
74 free_ind_table(void *idesc)
79 static __rte_always_inline void
80 do_flush_shadow_used_ring_split(struct virtio_net *dev,
81 struct vhost_virtqueue *vq,
82 uint16_t to, uint16_t from, uint16_t size)
84 rte_memcpy(&vq->used->ring[to],
85 &vq->shadow_used_split[from],
86 size * sizeof(struct vring_used_elem));
87 vhost_log_cache_used_vring(dev, vq,
88 offsetof(struct vring_used, ring[to]),
89 size * sizeof(struct vring_used_elem));
92 static __rte_always_inline void
93 flush_shadow_used_ring_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
95 uint16_t used_idx = vq->last_used_idx & (vq->size - 1);
97 if (used_idx + vq->shadow_used_idx <= vq->size) {
98 do_flush_shadow_used_ring_split(dev, vq, used_idx, 0,
103 /* update used ring interval [used_idx, vq->size] */
104 size = vq->size - used_idx;
105 do_flush_shadow_used_ring_split(dev, vq, used_idx, 0, size);
107 /* update the left half used ring interval [0, left_size] */
108 do_flush_shadow_used_ring_split(dev, vq, 0, size,
109 vq->shadow_used_idx - size);
111 vq->last_used_idx += vq->shadow_used_idx;
115 vhost_log_cache_sync(dev, vq);
117 *(volatile uint16_t *)&vq->used->idx += vq->shadow_used_idx;
118 vq->shadow_used_idx = 0;
119 vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
120 sizeof(vq->used->idx));
123 static __rte_always_inline void
124 update_shadow_used_ring_split(struct vhost_virtqueue *vq,
125 uint16_t desc_idx, uint32_t len)
127 uint16_t i = vq->shadow_used_idx++;
129 vq->shadow_used_split[i].id = desc_idx;
130 vq->shadow_used_split[i].len = len;
133 static __rte_always_inline void
134 flush_shadow_used_ring_packed(struct virtio_net *dev,
135 struct vhost_virtqueue *vq)
138 uint16_t used_idx = vq->last_used_idx;
140 /* Split loop in two to save memory barriers */
141 for (i = 0; i < vq->shadow_used_idx; i++) {
142 vq->desc_packed[used_idx].id = vq->shadow_used_packed[i].id;
143 vq->desc_packed[used_idx].len = vq->shadow_used_packed[i].len;
145 used_idx += vq->shadow_used_packed[i].count;
146 if (used_idx >= vq->size)
147 used_idx -= vq->size;
152 for (i = 0; i < vq->shadow_used_idx; i++) {
155 if (vq->shadow_used_packed[i].len)
156 flags = VRING_DESC_F_WRITE;
160 if (vq->used_wrap_counter) {
161 flags |= VRING_DESC_F_USED;
162 flags |= VRING_DESC_F_AVAIL;
164 flags &= ~VRING_DESC_F_USED;
165 flags &= ~VRING_DESC_F_AVAIL;
168 vq->desc_packed[vq->last_used_idx].flags = flags;
170 vhost_log_cache_used_vring(dev, vq,
172 sizeof(struct vring_packed_desc),
173 sizeof(struct vring_packed_desc));
175 vq->last_used_idx += vq->shadow_used_packed[i].count;
176 if (vq->last_used_idx >= vq->size) {
177 vq->used_wrap_counter ^= 1;
178 vq->last_used_idx -= vq->size;
183 vq->shadow_used_idx = 0;
184 vhost_log_cache_sync(dev, vq);
187 static __rte_always_inline void
188 update_shadow_used_ring_packed(struct vhost_virtqueue *vq,
189 uint16_t desc_idx, uint32_t len, uint16_t count)
191 uint16_t i = vq->shadow_used_idx++;
193 vq->shadow_used_packed[i].id = desc_idx;
194 vq->shadow_used_packed[i].len = len;
195 vq->shadow_used_packed[i].count = count;
199 do_data_copy_enqueue(struct virtio_net *dev, struct vhost_virtqueue *vq)
201 struct batch_copy_elem *elem = vq->batch_copy_elems;
202 uint16_t count = vq->batch_copy_nb_elems;
205 for (i = 0; i < count; i++) {
206 rte_memcpy(elem[i].dst, elem[i].src, elem[i].len);
207 vhost_log_cache_write(dev, vq, elem[i].log_addr, elem[i].len);
208 PRINT_PACKET(dev, (uintptr_t)elem[i].dst, elem[i].len, 0);
211 vq->batch_copy_nb_elems = 0;
215 do_data_copy_dequeue(struct vhost_virtqueue *vq)
217 struct batch_copy_elem *elem = vq->batch_copy_elems;
218 uint16_t count = vq->batch_copy_nb_elems;
221 for (i = 0; i < count; i++)
222 rte_memcpy(elem[i].dst, elem[i].src, elem[i].len);
224 vq->batch_copy_nb_elems = 0;
227 /* avoid write operation when necessary, to lessen cache issues */
228 #define ASSIGN_UNLESS_EQUAL(var, val) do { \
229 if ((var) != (val)) \
233 static __rte_always_inline void
234 virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
236 uint64_t csum_l4 = m_buf->ol_flags & PKT_TX_L4_MASK;
238 if (m_buf->ol_flags & PKT_TX_TCP_SEG)
239 csum_l4 |= PKT_TX_TCP_CKSUM;
242 net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
243 net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len;
246 case PKT_TX_TCP_CKSUM:
247 net_hdr->csum_offset = (offsetof(struct tcp_hdr,
250 case PKT_TX_UDP_CKSUM:
251 net_hdr->csum_offset = (offsetof(struct udp_hdr,
254 case PKT_TX_SCTP_CKSUM:
255 net_hdr->csum_offset = (offsetof(struct sctp_hdr,
260 ASSIGN_UNLESS_EQUAL(net_hdr->csum_start, 0);
261 ASSIGN_UNLESS_EQUAL(net_hdr->csum_offset, 0);
262 ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0);
265 /* IP cksum verification cannot be bypassed, then calculate here */
266 if (m_buf->ol_flags & PKT_TX_IP_CKSUM) {
267 struct ipv4_hdr *ipv4_hdr;
269 ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct ipv4_hdr *,
271 ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
274 if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
275 if (m_buf->ol_flags & PKT_TX_IPV4)
276 net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
278 net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
279 net_hdr->gso_size = m_buf->tso_segsz;
280 net_hdr->hdr_len = m_buf->l2_len + m_buf->l3_len
282 } else if (m_buf->ol_flags & PKT_TX_UDP_SEG) {
283 net_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
284 net_hdr->gso_size = m_buf->tso_segsz;
285 net_hdr->hdr_len = m_buf->l2_len + m_buf->l3_len +
288 ASSIGN_UNLESS_EQUAL(net_hdr->gso_type, 0);
289 ASSIGN_UNLESS_EQUAL(net_hdr->gso_size, 0);
290 ASSIGN_UNLESS_EQUAL(net_hdr->hdr_len, 0);
294 static __rte_always_inline int
295 map_one_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
296 struct buf_vector *buf_vec, uint16_t *vec_idx,
297 uint64_t desc_iova, uint64_t desc_len, uint8_t perm)
299 uint16_t vec_id = *vec_idx;
303 uint64_t desc_chunck_len = desc_len;
305 if (unlikely(vec_id >= BUF_VECTOR_MAX))
308 desc_addr = vhost_iova_to_vva(dev, vq,
312 if (unlikely(!desc_addr))
315 buf_vec[vec_id].buf_iova = desc_iova;
316 buf_vec[vec_id].buf_addr = desc_addr;
317 buf_vec[vec_id].buf_len = desc_chunck_len;
319 desc_len -= desc_chunck_len;
320 desc_iova += desc_chunck_len;
328 static __rte_always_inline int
329 fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
330 uint32_t avail_idx, uint16_t *vec_idx,
331 struct buf_vector *buf_vec, uint16_t *desc_chain_head,
332 uint32_t *desc_chain_len, uint8_t perm)
334 uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
335 uint16_t vec_id = *vec_idx;
338 uint32_t nr_descs = vq->size;
340 struct vring_desc *descs = vq->desc;
341 struct vring_desc *idesc = NULL;
343 if (unlikely(idx >= vq->size))
346 *desc_chain_head = idx;
348 if (vq->desc[idx].flags & VRING_DESC_F_INDIRECT) {
349 dlen = vq->desc[idx].len;
350 nr_descs = dlen / sizeof(struct vring_desc);
351 if (unlikely(nr_descs > vq->size))
354 descs = (struct vring_desc *)(uintptr_t)
355 vhost_iova_to_vva(dev, vq, vq->desc[idx].addr,
358 if (unlikely(!descs))
361 if (unlikely(dlen < vq->desc[idx].len)) {
363 * The indirect desc table is not contiguous
364 * in process VA space, we have to copy it.
366 idesc = alloc_copy_ind_table(dev, vq,
367 vq->desc[idx].addr, vq->desc[idx].len);
368 if (unlikely(!idesc))
378 if (unlikely(idx >= nr_descs || cnt++ >= nr_descs)) {
379 free_ind_table(idesc);
383 len += descs[idx].len;
385 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
386 descs[idx].addr, descs[idx].len,
388 free_ind_table(idesc);
392 if ((descs[idx].flags & VRING_DESC_F_NEXT) == 0)
395 idx = descs[idx].next;
398 *desc_chain_len = len;
401 if (unlikely(!!idesc))
402 free_ind_table(idesc);
408 * Returns -1 on fail, 0 on success
411 reserve_avail_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
412 uint32_t size, struct buf_vector *buf_vec,
413 uint16_t *num_buffers, uint16_t avail_head,
417 uint16_t vec_idx = 0;
418 uint16_t max_tries, tries = 0;
420 uint16_t head_idx = 0;
424 cur_idx = vq->last_avail_idx;
426 if (rxvq_is_mergeable(dev))
427 max_tries = vq->size - 1;
432 if (unlikely(cur_idx == avail_head))
435 * if we tried all available ring items, and still
436 * can't get enough buf, it means something abnormal
439 if (unlikely(++tries > max_tries))
442 if (unlikely(fill_vec_buf_split(dev, vq, cur_idx,
445 VHOST_ACCESS_RW) < 0))
447 len = RTE_MIN(len, size);
448 update_shadow_used_ring_split(vq, head_idx, len);
460 static __rte_always_inline int
461 fill_vec_buf_packed_indirect(struct virtio_net *dev,
462 struct vhost_virtqueue *vq,
463 struct vring_packed_desc *desc, uint16_t *vec_idx,
464 struct buf_vector *buf_vec, uint32_t *len, uint8_t perm)
468 uint16_t vec_id = *vec_idx;
470 struct vring_packed_desc *descs, *idescs = NULL;
473 descs = (struct vring_packed_desc *)(uintptr_t)
474 vhost_iova_to_vva(dev, vq, desc->addr, &dlen, VHOST_ACCESS_RO);
475 if (unlikely(!descs))
478 if (unlikely(dlen < desc->len)) {
480 * The indirect desc table is not contiguous
481 * in process VA space, we have to copy it.
483 idescs = alloc_copy_ind_table(dev, vq, desc->addr, desc->len);
484 if (unlikely(!idescs))
490 nr_descs = desc->len / sizeof(struct vring_packed_desc);
491 if (unlikely(nr_descs >= vq->size)) {
492 free_ind_table(idescs);
496 for (i = 0; i < nr_descs; i++) {
497 if (unlikely(vec_id >= BUF_VECTOR_MAX)) {
498 free_ind_table(idescs);
502 *len += descs[i].len;
503 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
504 descs[i].addr, descs[i].len,
510 if (unlikely(!!idescs))
511 free_ind_table(idescs);
516 static __rte_always_inline int
517 fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
518 uint16_t avail_idx, uint16_t *desc_count,
519 struct buf_vector *buf_vec, uint16_t *vec_idx,
520 uint16_t *buf_id, uint32_t *len, uint8_t perm)
522 bool wrap_counter = vq->avail_wrap_counter;
523 struct vring_packed_desc *descs = vq->desc_packed;
524 uint16_t vec_id = *vec_idx;
526 if (avail_idx < vq->last_avail_idx)
529 if (unlikely(!desc_is_avail(&descs[avail_idx], wrap_counter)))
533 * The ordering between desc flags and desc
534 * content reads need to be enforced.
542 if (unlikely(vec_id >= BUF_VECTOR_MAX))
545 if (unlikely(*desc_count >= vq->size))
549 *buf_id = descs[avail_idx].id;
551 if (descs[avail_idx].flags & VRING_DESC_F_INDIRECT) {
552 if (unlikely(fill_vec_buf_packed_indirect(dev, vq,
558 *len += descs[avail_idx].len;
560 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
561 descs[avail_idx].addr,
562 descs[avail_idx].len,
567 if ((descs[avail_idx].flags & VRING_DESC_F_NEXT) == 0)
570 if (++avail_idx >= vq->size) {
571 avail_idx -= vq->size;
582 * Returns -1 on fail, 0 on success
585 reserve_avail_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
586 uint32_t size, struct buf_vector *buf_vec,
587 uint16_t *nr_vec, uint16_t *num_buffers,
591 uint16_t vec_idx = 0;
592 uint16_t max_tries, tries = 0;
599 avail_idx = vq->last_avail_idx;
601 if (rxvq_is_mergeable(dev))
602 max_tries = vq->size - 1;
608 * if we tried all available ring items, and still
609 * can't get enough buf, it means something abnormal
612 if (unlikely(++tries > max_tries))
615 if (unlikely(fill_vec_buf_packed(dev, vq,
616 avail_idx, &desc_count,
619 VHOST_ACCESS_RW) < 0))
622 len = RTE_MIN(len, size);
623 update_shadow_used_ring_packed(vq, buf_id, len, desc_count);
626 avail_idx += desc_count;
627 if (avail_idx >= vq->size)
628 avail_idx -= vq->size;
630 *nr_descs += desc_count;
639 static __rte_always_inline int
640 copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
641 struct rte_mbuf *m, struct buf_vector *buf_vec,
642 uint16_t nr_vec, uint16_t num_buffers)
644 uint32_t vec_idx = 0;
645 uint32_t mbuf_offset, mbuf_avail;
646 uint32_t buf_offset, buf_avail;
647 uint64_t buf_addr, buf_iova, buf_len;
650 struct rte_mbuf *hdr_mbuf;
651 struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
652 struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL;
655 if (unlikely(m == NULL)) {
660 buf_addr = buf_vec[vec_idx].buf_addr;
661 buf_iova = buf_vec[vec_idx].buf_iova;
662 buf_len = buf_vec[vec_idx].buf_len;
665 rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
667 if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) {
674 if (unlikely(buf_len < dev->vhost_hlen))
677 hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)hdr_addr;
679 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
680 dev->vid, num_buffers);
682 if (unlikely(buf_len < dev->vhost_hlen)) {
683 buf_offset = dev->vhost_hlen - buf_len;
685 buf_addr = buf_vec[vec_idx].buf_addr;
686 buf_iova = buf_vec[vec_idx].buf_iova;
687 buf_len = buf_vec[vec_idx].buf_len;
688 buf_avail = buf_len - buf_offset;
690 buf_offset = dev->vhost_hlen;
691 buf_avail = buf_len - dev->vhost_hlen;
694 mbuf_avail = rte_pktmbuf_data_len(m);
696 while (mbuf_avail != 0 || m->next != NULL) {
697 /* done with current buf, get the next one */
698 if (buf_avail == 0) {
700 if (unlikely(vec_idx >= nr_vec)) {
705 buf_addr = buf_vec[vec_idx].buf_addr;
706 buf_iova = buf_vec[vec_idx].buf_iova;
707 buf_len = buf_vec[vec_idx].buf_len;
709 /* Prefetch next buffer address. */
710 if (vec_idx + 1 < nr_vec)
711 rte_prefetch0((void *)(uintptr_t)
712 buf_vec[vec_idx + 1].buf_addr);
717 /* done with current mbuf, get the next one */
718 if (mbuf_avail == 0) {
722 mbuf_avail = rte_pktmbuf_data_len(m);
726 virtio_enqueue_offload(hdr_mbuf, &hdr->hdr);
727 if (rxvq_is_mergeable(dev))
728 ASSIGN_UNLESS_EQUAL(hdr->num_buffers,
731 if (unlikely(hdr == &tmp_hdr)) {
733 uint64_t remain = dev->vhost_hlen;
734 uint64_t src = (uint64_t)(uintptr_t)hdr, dst;
735 uint64_t iova = buf_vec[0].buf_iova;
736 uint16_t hdr_vec_idx = 0;
739 len = RTE_MIN(remain,
740 buf_vec[hdr_vec_idx].buf_len);
741 dst = buf_vec[hdr_vec_idx].buf_addr;
742 rte_memcpy((void *)(uintptr_t)dst,
743 (void *)(uintptr_t)src,
746 PRINT_PACKET(dev, (uintptr_t)dst,
748 vhost_log_cache_write(dev, vq,
757 PRINT_PACKET(dev, (uintptr_t)hdr_addr,
759 vhost_log_cache_write(dev, vq,
767 cpy_len = RTE_MIN(buf_avail, mbuf_avail);
769 if (likely(cpy_len > MAX_BATCH_LEN ||
770 vq->batch_copy_nb_elems >= vq->size)) {
771 rte_memcpy((void *)((uintptr_t)(buf_addr + buf_offset)),
772 rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
774 vhost_log_cache_write(dev, vq, buf_iova + buf_offset,
776 PRINT_PACKET(dev, (uintptr_t)(buf_addr + buf_offset),
779 batch_copy[vq->batch_copy_nb_elems].dst =
780 (void *)((uintptr_t)(buf_addr + buf_offset));
781 batch_copy[vq->batch_copy_nb_elems].src =
782 rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
783 batch_copy[vq->batch_copy_nb_elems].log_addr =
784 buf_iova + buf_offset;
785 batch_copy[vq->batch_copy_nb_elems].len = cpy_len;
786 vq->batch_copy_nb_elems++;
789 mbuf_avail -= cpy_len;
790 mbuf_offset += cpy_len;
791 buf_avail -= cpy_len;
792 buf_offset += cpy_len;
800 static __rte_always_inline uint32_t
801 virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
802 struct rte_mbuf **pkts, uint32_t count)
804 uint32_t pkt_idx = 0;
805 uint16_t num_buffers;
806 struct buf_vector buf_vec[BUF_VECTOR_MAX];
809 rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
810 avail_head = *((volatile uint16_t *)&vq->avail->idx);
813 * The ordering between avail index and
814 * desc reads needs to be enforced.
818 for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
819 uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
822 if (unlikely(reserve_avail_buf_split(dev, vq,
823 pkt_len, buf_vec, &num_buffers,
824 avail_head, &nr_vec) < 0)) {
825 VHOST_LOG_DEBUG(VHOST_DATA,
826 "(%d) failed to get enough desc from vring\n",
828 vq->shadow_used_idx -= num_buffers;
832 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
834 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
835 dev->vid, vq->last_avail_idx,
836 vq->last_avail_idx + num_buffers);
838 if (copy_mbuf_to_desc(dev, vq, pkts[pkt_idx],
841 vq->shadow_used_idx -= num_buffers;
845 vq->last_avail_idx += num_buffers;
848 do_data_copy_enqueue(dev, vq);
850 if (likely(vq->shadow_used_idx)) {
851 flush_shadow_used_ring_split(dev, vq);
852 vhost_vring_call_split(dev, vq);
858 static __rte_always_inline uint32_t
859 virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
860 struct rte_mbuf **pkts, uint32_t count)
862 uint32_t pkt_idx = 0;
863 uint16_t num_buffers;
864 struct buf_vector buf_vec[BUF_VECTOR_MAX];
866 for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
867 uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
869 uint16_t nr_descs = 0;
871 if (unlikely(reserve_avail_buf_packed(dev, vq,
872 pkt_len, buf_vec, &nr_vec,
873 &num_buffers, &nr_descs) < 0)) {
874 VHOST_LOG_DEBUG(VHOST_DATA,
875 "(%d) failed to get enough desc from vring\n",
877 vq->shadow_used_idx -= num_buffers;
881 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
883 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
884 dev->vid, vq->last_avail_idx,
885 vq->last_avail_idx + num_buffers);
887 if (copy_mbuf_to_desc(dev, vq, pkts[pkt_idx],
890 vq->shadow_used_idx -= num_buffers;
894 vq->last_avail_idx += nr_descs;
895 if (vq->last_avail_idx >= vq->size) {
896 vq->last_avail_idx -= vq->size;
897 vq->avail_wrap_counter ^= 1;
901 do_data_copy_enqueue(dev, vq);
903 if (likely(vq->shadow_used_idx)) {
904 flush_shadow_used_ring_packed(dev, vq);
905 vhost_vring_call_packed(dev, vq);
911 static __rte_always_inline uint32_t
912 virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
913 struct rte_mbuf **pkts, uint32_t count)
915 struct vhost_virtqueue *vq;
918 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
919 if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
920 RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
921 dev->vid, __func__, queue_id);
925 vq = dev->virtqueue[queue_id];
927 rte_spinlock_lock(&vq->access_lock);
929 if (unlikely(vq->enabled == 0))
930 goto out_access_unlock;
932 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
933 vhost_user_iotlb_rd_lock(vq);
935 if (unlikely(vq->access_ok == 0))
936 if (unlikely(vring_translate(dev, vq) < 0))
939 count = RTE_MIN((uint32_t)MAX_PKT_BURST, count);
943 if (vq_is_packed(dev))
944 nb_tx = virtio_dev_rx_packed(dev, vq, pkts, count);
946 nb_tx = virtio_dev_rx_split(dev, vq, pkts, count);
949 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
950 vhost_user_iotlb_rd_unlock(vq);
953 rte_spinlock_unlock(&vq->access_lock);
959 rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
960 struct rte_mbuf **pkts, uint16_t count)
962 struct virtio_net *dev = get_device(vid);
967 if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
968 RTE_LOG(ERR, VHOST_DATA,
969 "(%d) %s: built-in vhost net backend is disabled.\n",
974 return virtio_dev_rx(dev, queue_id, pkts, count);
978 virtio_net_with_host_offload(struct virtio_net *dev)
981 ((1ULL << VIRTIO_NET_F_CSUM) |
982 (1ULL << VIRTIO_NET_F_HOST_ECN) |
983 (1ULL << VIRTIO_NET_F_HOST_TSO4) |
984 (1ULL << VIRTIO_NET_F_HOST_TSO6) |
985 (1ULL << VIRTIO_NET_F_HOST_UFO)))
992 parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
994 struct ipv4_hdr *ipv4_hdr;
995 struct ipv6_hdr *ipv6_hdr;
997 struct ether_hdr *eth_hdr;
1000 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
1002 m->l2_len = sizeof(struct ether_hdr);
1003 ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
1005 if (ethertype == ETHER_TYPE_VLAN) {
1006 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
1008 m->l2_len += sizeof(struct vlan_hdr);
1009 ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
1012 l3_hdr = (char *)eth_hdr + m->l2_len;
1014 switch (ethertype) {
1015 case ETHER_TYPE_IPv4:
1017 *l4_proto = ipv4_hdr->next_proto_id;
1018 m->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
1019 *l4_hdr = (char *)l3_hdr + m->l3_len;
1020 m->ol_flags |= PKT_TX_IPV4;
1022 case ETHER_TYPE_IPv6:
1024 *l4_proto = ipv6_hdr->proto;
1025 m->l3_len = sizeof(struct ipv6_hdr);
1026 *l4_hdr = (char *)l3_hdr + m->l3_len;
1027 m->ol_flags |= PKT_TX_IPV6;
1037 static __rte_always_inline void
1038 vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
1040 uint16_t l4_proto = 0;
1041 void *l4_hdr = NULL;
1042 struct tcp_hdr *tcp_hdr = NULL;
1044 if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
1047 parse_ethernet(m, &l4_proto, &l4_hdr);
1048 if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
1049 if (hdr->csum_start == (m->l2_len + m->l3_len)) {
1050 switch (hdr->csum_offset) {
1051 case (offsetof(struct tcp_hdr, cksum)):
1052 if (l4_proto == IPPROTO_TCP)
1053 m->ol_flags |= PKT_TX_TCP_CKSUM;
1055 case (offsetof(struct udp_hdr, dgram_cksum)):
1056 if (l4_proto == IPPROTO_UDP)
1057 m->ol_flags |= PKT_TX_UDP_CKSUM;
1059 case (offsetof(struct sctp_hdr, cksum)):
1060 if (l4_proto == IPPROTO_SCTP)
1061 m->ol_flags |= PKT_TX_SCTP_CKSUM;
1069 if (l4_hdr && hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
1070 switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
1071 case VIRTIO_NET_HDR_GSO_TCPV4:
1072 case VIRTIO_NET_HDR_GSO_TCPV6:
1074 m->ol_flags |= PKT_TX_TCP_SEG;
1075 m->tso_segsz = hdr->gso_size;
1076 m->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
1078 case VIRTIO_NET_HDR_GSO_UDP:
1079 m->ol_flags |= PKT_TX_UDP_SEG;
1080 m->tso_segsz = hdr->gso_size;
1081 m->l4_len = sizeof(struct udp_hdr);
1084 RTE_LOG(WARNING, VHOST_DATA,
1085 "unsupported gso type %u.\n", hdr->gso_type);
1091 static __rte_always_inline void
1092 put_zmbuf(struct zcopy_mbuf *zmbuf)
1097 static __rte_always_inline int
1098 copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
1099 struct buf_vector *buf_vec, uint16_t nr_vec,
1100 struct rte_mbuf *m, struct rte_mempool *mbuf_pool)
1102 uint32_t buf_avail, buf_offset;
1103 uint64_t buf_addr, buf_iova, buf_len;
1104 uint32_t mbuf_avail, mbuf_offset;
1106 struct rte_mbuf *cur = m, *prev = m;
1107 struct virtio_net_hdr tmp_hdr;
1108 struct virtio_net_hdr *hdr = NULL;
1109 /* A counter to avoid desc dead loop chain */
1110 uint16_t vec_idx = 0;
1111 struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
1114 buf_addr = buf_vec[vec_idx].buf_addr;
1115 buf_iova = buf_vec[vec_idx].buf_iova;
1116 buf_len = buf_vec[vec_idx].buf_len;
1118 if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) {
1123 if (likely(nr_vec > 1))
1124 rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
1126 if (virtio_net_with_host_offload(dev)) {
1127 if (unlikely(buf_len < sizeof(struct virtio_net_hdr))) {
1129 uint64_t remain = sizeof(struct virtio_net_hdr);
1131 uint64_t dst = (uint64_t)(uintptr_t)&tmp_hdr;
1132 uint16_t hdr_vec_idx = 0;
1135 * No luck, the virtio-net header doesn't fit
1136 * in a contiguous virtual area.
1139 len = RTE_MIN(remain,
1140 buf_vec[hdr_vec_idx].buf_len);
1141 src = buf_vec[hdr_vec_idx].buf_addr;
1142 rte_memcpy((void *)(uintptr_t)dst,
1143 (void *)(uintptr_t)src, len);
1152 hdr = (struct virtio_net_hdr *)((uintptr_t)buf_addr);
1158 * A virtio driver normally uses at least 2 desc buffers
1159 * for Tx: the first for storing the header, and others
1160 * for storing the data.
1162 if (unlikely(buf_len < dev->vhost_hlen)) {
1163 buf_offset = dev->vhost_hlen - buf_len;
1165 buf_addr = buf_vec[vec_idx].buf_addr;
1166 buf_iova = buf_vec[vec_idx].buf_iova;
1167 buf_len = buf_vec[vec_idx].buf_len;
1168 buf_avail = buf_len - buf_offset;
1169 } else if (buf_len == dev->vhost_hlen) {
1170 if (unlikely(++vec_idx >= nr_vec))
1172 buf_addr = buf_vec[vec_idx].buf_addr;
1173 buf_iova = buf_vec[vec_idx].buf_iova;
1174 buf_len = buf_vec[vec_idx].buf_len;
1177 buf_avail = buf_len;
1179 buf_offset = dev->vhost_hlen;
1180 buf_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
1183 rte_prefetch0((void *)(uintptr_t)
1184 (buf_addr + buf_offset));
1187 (uintptr_t)(buf_addr + buf_offset),
1188 (uint32_t)buf_avail, 0);
1191 mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
1195 cpy_len = RTE_MIN(buf_avail, mbuf_avail);
1198 * A desc buf might across two host physical pages that are
1199 * not continuous. In such case (gpa_to_hpa returns 0), data
1200 * will be copied even though zero copy is enabled.
1202 if (unlikely(dev->dequeue_zero_copy && (hpa = gpa_to_hpa(dev,
1203 buf_iova + buf_offset, cpy_len)))) {
1204 cur->data_len = cpy_len;
1207 (void *)(uintptr_t)(buf_addr + buf_offset);
1208 cur->buf_iova = hpa;
1211 * In zero copy mode, one mbuf can only reference data
1212 * for one or partial of one desc buff.
1214 mbuf_avail = cpy_len;
1216 if (likely(cpy_len > MAX_BATCH_LEN ||
1217 vq->batch_copy_nb_elems >= vq->size ||
1218 (hdr && cur == m))) {
1219 rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *,
1221 (void *)((uintptr_t)(buf_addr +
1225 batch_copy[vq->batch_copy_nb_elems].dst =
1226 rte_pktmbuf_mtod_offset(cur, void *,
1228 batch_copy[vq->batch_copy_nb_elems].src =
1229 (void *)((uintptr_t)(buf_addr +
1231 batch_copy[vq->batch_copy_nb_elems].len =
1233 vq->batch_copy_nb_elems++;
1237 mbuf_avail -= cpy_len;
1238 mbuf_offset += cpy_len;
1239 buf_avail -= cpy_len;
1240 buf_offset += cpy_len;
1242 /* This buf reaches to its end, get the next one */
1243 if (buf_avail == 0) {
1244 if (++vec_idx >= nr_vec)
1247 buf_addr = buf_vec[vec_idx].buf_addr;
1248 buf_iova = buf_vec[vec_idx].buf_iova;
1249 buf_len = buf_vec[vec_idx].buf_len;
1252 * Prefecth desc n + 1 buffer while
1253 * desc n buffer is processed.
1255 if (vec_idx + 1 < nr_vec)
1256 rte_prefetch0((void *)(uintptr_t)
1257 buf_vec[vec_idx + 1].buf_addr);
1260 buf_avail = buf_len;
1262 PRINT_PACKET(dev, (uintptr_t)buf_addr,
1263 (uint32_t)buf_avail, 0);
1267 * This mbuf reaches to its end, get a new one
1268 * to hold more data.
1270 if (mbuf_avail == 0) {
1271 cur = rte_pktmbuf_alloc(mbuf_pool);
1272 if (unlikely(cur == NULL)) {
1273 RTE_LOG(ERR, VHOST_DATA, "Failed to "
1274 "allocate memory for mbuf.\n");
1278 if (unlikely(dev->dequeue_zero_copy))
1279 rte_mbuf_refcnt_update(cur, 1);
1282 prev->data_len = mbuf_offset;
1284 m->pkt_len += mbuf_offset;
1288 mbuf_avail = cur->buf_len - RTE_PKTMBUF_HEADROOM;
1292 prev->data_len = mbuf_offset;
1293 m->pkt_len += mbuf_offset;
1296 vhost_dequeue_offload(hdr, m);
1303 static __rte_always_inline struct zcopy_mbuf *
1304 get_zmbuf(struct vhost_virtqueue *vq)
1310 /* search [last_zmbuf_idx, zmbuf_size) */
1311 i = vq->last_zmbuf_idx;
1312 last = vq->zmbuf_size;
1315 for (; i < last; i++) {
1316 if (vq->zmbufs[i].in_use == 0) {
1317 vq->last_zmbuf_idx = i + 1;
1318 vq->zmbufs[i].in_use = 1;
1319 return &vq->zmbufs[i];
1325 /* search [0, last_zmbuf_idx) */
1327 last = vq->last_zmbuf_idx;
1334 static __rte_always_inline bool
1335 mbuf_is_consumed(struct rte_mbuf *m)
1338 if (rte_mbuf_refcnt_read(m) > 1)
1346 static __rte_always_inline void
1347 restore_mbuf(struct rte_mbuf *m)
1349 uint32_t mbuf_size, priv_size;
1352 priv_size = rte_pktmbuf_priv_size(m->pool);
1353 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
1354 /* start of buffer is after mbuf structure and priv data */
1356 m->buf_addr = (char *)m + mbuf_size;
1357 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
1362 static __rte_always_inline uint16_t
1363 virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
1364 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1367 uint16_t free_entries;
1369 if (unlikely(dev->dequeue_zero_copy)) {
1370 struct zcopy_mbuf *zmbuf, *next;
1372 for (zmbuf = TAILQ_FIRST(&vq->zmbuf_list);
1373 zmbuf != NULL; zmbuf = next) {
1374 next = TAILQ_NEXT(zmbuf, next);
1376 if (mbuf_is_consumed(zmbuf->mbuf)) {
1377 update_shadow_used_ring_split(vq,
1378 zmbuf->desc_idx, 0);
1379 TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
1380 restore_mbuf(zmbuf->mbuf);
1381 rte_pktmbuf_free(zmbuf->mbuf);
1387 if (likely(vq->shadow_used_idx)) {
1388 flush_shadow_used_ring_split(dev, vq);
1389 vhost_vring_call_split(dev, vq);
1393 rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
1395 free_entries = *((volatile uint16_t *)&vq->avail->idx) -
1397 if (free_entries == 0)
1401 * The ordering between avail index and
1402 * desc reads needs to be enforced.
1406 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
1408 count = RTE_MIN(count, MAX_PKT_BURST);
1409 count = RTE_MIN(count, free_entries);
1410 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
1413 for (i = 0; i < count; i++) {
1414 struct buf_vector buf_vec[BUF_VECTOR_MAX];
1417 uint16_t nr_vec = 0;
1420 if (unlikely(fill_vec_buf_split(dev, vq,
1421 vq->last_avail_idx + i,
1423 &head_idx, &dummy_len,
1424 VHOST_ACCESS_RO) < 0))
1427 if (likely(dev->dequeue_zero_copy == 0))
1428 update_shadow_used_ring_split(vq, head_idx, 0);
1430 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
1432 pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
1433 if (unlikely(pkts[i] == NULL)) {
1434 RTE_LOG(ERR, VHOST_DATA,
1435 "Failed to allocate memory for mbuf.\n");
1439 err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i],
1441 if (unlikely(err)) {
1442 rte_pktmbuf_free(pkts[i]);
1446 if (unlikely(dev->dequeue_zero_copy)) {
1447 struct zcopy_mbuf *zmbuf;
1449 zmbuf = get_zmbuf(vq);
1451 rte_pktmbuf_free(pkts[i]);
1454 zmbuf->mbuf = pkts[i];
1455 zmbuf->desc_idx = head_idx;
1458 * Pin lock the mbuf; we will check later to see
1459 * whether the mbuf is freed (when we are the last
1460 * user) or not. If that's the case, we then could
1461 * update the used ring safely.
1463 rte_mbuf_refcnt_update(pkts[i], 1);
1466 TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
1469 vq->last_avail_idx += i;
1471 if (likely(dev->dequeue_zero_copy == 0)) {
1472 do_data_copy_dequeue(vq);
1473 if (unlikely(i < count))
1474 vq->shadow_used_idx = i;
1475 if (likely(vq->shadow_used_idx)) {
1476 flush_shadow_used_ring_split(dev, vq);
1477 vhost_vring_call_split(dev, vq);
1484 static __rte_always_inline uint16_t
1485 virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
1486 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1490 rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]);
1492 if (unlikely(dev->dequeue_zero_copy)) {
1493 struct zcopy_mbuf *zmbuf, *next;
1495 for (zmbuf = TAILQ_FIRST(&vq->zmbuf_list);
1496 zmbuf != NULL; zmbuf = next) {
1497 next = TAILQ_NEXT(zmbuf, next);
1499 if (mbuf_is_consumed(zmbuf->mbuf)) {
1500 update_shadow_used_ring_packed(vq,
1505 TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
1506 restore_mbuf(zmbuf->mbuf);
1507 rte_pktmbuf_free(zmbuf->mbuf);
1513 if (likely(vq->shadow_used_idx)) {
1514 flush_shadow_used_ring_packed(dev, vq);
1515 vhost_vring_call_packed(dev, vq);
1519 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
1521 count = RTE_MIN(count, MAX_PKT_BURST);
1522 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
1525 for (i = 0; i < count; i++) {
1526 struct buf_vector buf_vec[BUF_VECTOR_MAX];
1529 uint16_t desc_count, nr_vec = 0;
1532 if (unlikely(fill_vec_buf_packed(dev, vq,
1533 vq->last_avail_idx, &desc_count,
1535 &buf_id, &dummy_len,
1536 VHOST_ACCESS_RO) < 0))
1539 if (likely(dev->dequeue_zero_copy == 0))
1540 update_shadow_used_ring_packed(vq, buf_id, 0,
1543 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
1545 pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
1546 if (unlikely(pkts[i] == NULL)) {
1547 RTE_LOG(ERR, VHOST_DATA,
1548 "Failed to allocate memory for mbuf.\n");
1552 err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i],
1554 if (unlikely(err)) {
1555 rte_pktmbuf_free(pkts[i]);
1559 if (unlikely(dev->dequeue_zero_copy)) {
1560 struct zcopy_mbuf *zmbuf;
1562 zmbuf = get_zmbuf(vq);
1564 rte_pktmbuf_free(pkts[i]);
1567 zmbuf->mbuf = pkts[i];
1568 zmbuf->desc_idx = buf_id;
1569 zmbuf->desc_count = desc_count;
1572 * Pin lock the mbuf; we will check later to see
1573 * whether the mbuf is freed (when we are the last
1574 * user) or not. If that's the case, we then could
1575 * update the used ring safely.
1577 rte_mbuf_refcnt_update(pkts[i], 1);
1580 TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
1583 vq->last_avail_idx += desc_count;
1584 if (vq->last_avail_idx >= vq->size) {
1585 vq->last_avail_idx -= vq->size;
1586 vq->avail_wrap_counter ^= 1;
1590 if (likely(dev->dequeue_zero_copy == 0)) {
1591 do_data_copy_dequeue(vq);
1592 if (unlikely(i < count))
1593 vq->shadow_used_idx = i;
1594 if (likely(vq->shadow_used_idx)) {
1595 flush_shadow_used_ring_packed(dev, vq);
1596 vhost_vring_call_packed(dev, vq);
1604 rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
1605 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1607 struct virtio_net *dev;
1608 struct rte_mbuf *rarp_mbuf = NULL;
1609 struct vhost_virtqueue *vq;
1611 dev = get_device(vid);
1615 if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
1616 RTE_LOG(ERR, VHOST_DATA,
1617 "(%d) %s: built-in vhost net backend is disabled.\n",
1618 dev->vid, __func__);
1622 if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) {
1623 RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
1624 dev->vid, __func__, queue_id);
1628 vq = dev->virtqueue[queue_id];
1630 if (unlikely(rte_spinlock_trylock(&vq->access_lock) == 0))
1633 if (unlikely(vq->enabled == 0)) {
1635 goto out_access_unlock;
1638 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
1639 vhost_user_iotlb_rd_lock(vq);
1641 if (unlikely(vq->access_ok == 0))
1642 if (unlikely(vring_translate(dev, vq) < 0)) {
1648 * Construct a RARP broadcast packet, and inject it to the "pkts"
1649 * array, to looks like that guest actually send such packet.
1651 * Check user_send_rarp() for more information.
1653 * broadcast_rarp shares a cacheline in the virtio_net structure
1654 * with some fields that are accessed during enqueue and
1655 * rte_atomic16_cmpset() causes a write if using cmpxchg. This could
1656 * result in false sharing between enqueue and dequeue.
1658 * Prevent unnecessary false sharing by reading broadcast_rarp first
1659 * and only performing cmpset if the read indicates it is likely to
1662 if (unlikely(rte_atomic16_read(&dev->broadcast_rarp) &&
1663 rte_atomic16_cmpset((volatile uint16_t *)
1664 &dev->broadcast_rarp.cnt, 1, 0))) {
1666 rarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);
1667 if (rarp_mbuf == NULL) {
1668 RTE_LOG(ERR, VHOST_DATA,
1669 "Failed to make RARP packet.\n");
1676 if (vq_is_packed(dev))
1677 count = virtio_dev_tx_packed(dev, vq, mbuf_pool, pkts, count);
1679 count = virtio_dev_tx_split(dev, vq, mbuf_pool, pkts, count);
1682 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
1683 vhost_user_iotlb_rd_unlock(vq);
1686 rte_spinlock_unlock(&vq->access_lock);
1688 if (unlikely(rarp_mbuf != NULL)) {
1690 * Inject it to the head of "pkts" array, so that switch's mac
1691 * learning table will get updated first.
1693 memmove(&pkts[1], pkts, count * sizeof(struct rte_mbuf *));
1694 pkts[0] = rarp_mbuf;