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, uint16_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, uint16_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 uint16_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 struct vring_desc *descs = vq->desc;
339 struct vring_desc *idesc = NULL;
341 *desc_chain_head = idx;
343 if (vq->desc[idx].flags & VRING_DESC_F_INDIRECT) {
344 dlen = vq->desc[idx].len;
345 descs = (struct vring_desc *)(uintptr_t)
346 vhost_iova_to_vva(dev, vq, vq->desc[idx].addr,
349 if (unlikely(!descs))
352 if (unlikely(dlen < vq->desc[idx].len)) {
354 * The indirect desc table is not contiguous
355 * in process VA space, we have to copy it.
357 idesc = alloc_copy_ind_table(dev, vq,
358 vq->desc[idx].addr, vq->desc[idx].len);
359 if (unlikely(!idesc))
369 if (unlikely(idx >= vq->size)) {
370 free_ind_table(idesc);
374 len += descs[idx].len;
376 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
377 descs[idx].addr, descs[idx].len,
379 free_ind_table(idesc);
383 if ((descs[idx].flags & VRING_DESC_F_NEXT) == 0)
386 idx = descs[idx].next;
389 *desc_chain_len = len;
392 if (unlikely(!!idesc))
393 free_ind_table(idesc);
399 * Returns -1 on fail, 0 on success
402 reserve_avail_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
403 uint32_t size, struct buf_vector *buf_vec,
404 uint16_t *num_buffers, uint16_t avail_head,
408 uint16_t vec_idx = 0;
409 uint16_t max_tries, tries = 0;
411 uint16_t head_idx = 0;
415 cur_idx = vq->last_avail_idx;
417 if (rxvq_is_mergeable(dev))
418 max_tries = vq->size;
423 if (unlikely(cur_idx == avail_head))
426 if (unlikely(fill_vec_buf_split(dev, vq, cur_idx,
429 VHOST_ACCESS_RW) < 0))
431 len = RTE_MIN(len, size);
432 update_shadow_used_ring_split(vq, head_idx, len);
440 * if we tried all available ring items, and still
441 * can't get enough buf, it means something abnormal
444 if (unlikely(tries > max_tries))
453 static __rte_always_inline int
454 fill_vec_buf_packed_indirect(struct virtio_net *dev,
455 struct vhost_virtqueue *vq,
456 struct vring_packed_desc *desc, uint16_t *vec_idx,
457 struct buf_vector *buf_vec, uint16_t *len, uint8_t perm)
461 uint16_t vec_id = *vec_idx;
463 struct vring_packed_desc *descs, *idescs = NULL;
466 descs = (struct vring_packed_desc *)(uintptr_t)
467 vhost_iova_to_vva(dev, vq, desc->addr, &dlen, VHOST_ACCESS_RO);
468 if (unlikely(!descs))
471 if (unlikely(dlen < desc->len)) {
473 * The indirect desc table is not contiguous
474 * in process VA space, we have to copy it.
476 idescs = alloc_copy_ind_table(dev, vq, desc->addr, desc->len);
477 if (unlikely(!idescs))
483 nr_descs = desc->len / sizeof(struct vring_packed_desc);
484 if (unlikely(nr_descs >= vq->size)) {
485 free_ind_table(idescs);
489 for (i = 0; i < nr_descs; i++) {
490 if (unlikely(vec_id >= BUF_VECTOR_MAX)) {
491 free_ind_table(idescs);
495 *len += descs[i].len;
496 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
497 descs[i].addr, descs[i].len,
503 if (unlikely(!!idescs))
504 free_ind_table(idescs);
509 static __rte_always_inline int
510 fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
511 uint16_t avail_idx, uint16_t *desc_count,
512 struct buf_vector *buf_vec, uint16_t *vec_idx,
513 uint16_t *buf_id, uint16_t *len, uint8_t perm)
515 bool wrap_counter = vq->avail_wrap_counter;
516 struct vring_packed_desc *descs = vq->desc_packed;
517 uint16_t vec_id = *vec_idx;
519 if (avail_idx < vq->last_avail_idx)
522 if (unlikely(!desc_is_avail(&descs[avail_idx], wrap_counter)))
528 if (unlikely(vec_id >= BUF_VECTOR_MAX))
532 *buf_id = descs[avail_idx].id;
534 if (descs[avail_idx].flags & VRING_DESC_F_INDIRECT) {
535 if (unlikely(fill_vec_buf_packed_indirect(dev, vq,
541 *len += descs[avail_idx].len;
543 if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
544 descs[avail_idx].addr,
545 descs[avail_idx].len,
550 if ((descs[avail_idx].flags & VRING_DESC_F_NEXT) == 0)
553 if (++avail_idx >= vq->size) {
554 avail_idx -= vq->size;
565 * Returns -1 on fail, 0 on success
568 reserve_avail_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
569 uint32_t size, struct buf_vector *buf_vec,
570 uint16_t *nr_vec, uint16_t *num_buffers,
574 uint16_t vec_idx = 0;
575 uint16_t max_tries, tries = 0;
582 avail_idx = vq->last_avail_idx;
584 if (rxvq_is_mergeable(dev))
585 max_tries = vq->size;
590 if (unlikely(fill_vec_buf_packed(dev, vq,
591 avail_idx, &desc_count,
594 VHOST_ACCESS_RO) < 0))
597 len = RTE_MIN(len, size);
598 update_shadow_used_ring_packed(vq, buf_id, len, desc_count);
601 avail_idx += desc_count;
602 if (avail_idx >= vq->size)
603 avail_idx -= vq->size;
605 *nr_descs += desc_count;
610 * if we tried all available ring items, and still
611 * can't get enough buf, it means something abnormal
614 if (unlikely(tries > max_tries))
623 static __rte_always_inline int
624 copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
625 struct rte_mbuf *m, struct buf_vector *buf_vec,
626 uint16_t nr_vec, uint16_t num_buffers)
628 uint32_t vec_idx = 0;
629 uint32_t mbuf_offset, mbuf_avail;
630 uint32_t buf_offset, buf_avail;
631 uint64_t buf_addr, buf_iova, buf_len;
634 struct rte_mbuf *hdr_mbuf;
635 struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
636 struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL;
639 if (unlikely(m == NULL)) {
644 buf_addr = buf_vec[vec_idx].buf_addr;
645 buf_iova = buf_vec[vec_idx].buf_iova;
646 buf_len = buf_vec[vec_idx].buf_len;
649 rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
651 if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) {
658 if (unlikely(buf_len < dev->vhost_hlen))
661 hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)hdr_addr;
663 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
664 dev->vid, num_buffers);
666 if (unlikely(buf_len < dev->vhost_hlen)) {
667 buf_offset = dev->vhost_hlen - buf_len;
669 buf_addr = buf_vec[vec_idx].buf_addr;
670 buf_iova = buf_vec[vec_idx].buf_iova;
671 buf_len = buf_vec[vec_idx].buf_len;
672 buf_avail = buf_len - buf_offset;
674 buf_offset = dev->vhost_hlen;
675 buf_avail = buf_len - dev->vhost_hlen;
678 mbuf_avail = rte_pktmbuf_data_len(m);
680 while (mbuf_avail != 0 || m->next != NULL) {
681 /* done with current buf, get the next one */
682 if (buf_avail == 0) {
684 if (unlikely(vec_idx >= nr_vec)) {
689 buf_addr = buf_vec[vec_idx].buf_addr;
690 buf_iova = buf_vec[vec_idx].buf_iova;
691 buf_len = buf_vec[vec_idx].buf_len;
693 /* Prefetch next buffer address. */
694 if (vec_idx + 1 < nr_vec)
695 rte_prefetch0((void *)(uintptr_t)
696 buf_vec[vec_idx + 1].buf_addr);
701 /* done with current mbuf, get the next one */
702 if (mbuf_avail == 0) {
706 mbuf_avail = rte_pktmbuf_data_len(m);
710 virtio_enqueue_offload(hdr_mbuf, &hdr->hdr);
711 if (rxvq_is_mergeable(dev))
712 ASSIGN_UNLESS_EQUAL(hdr->num_buffers,
715 if (unlikely(hdr == &tmp_hdr)) {
717 uint64_t remain = dev->vhost_hlen;
718 uint64_t src = (uint64_t)(uintptr_t)hdr, dst;
719 uint64_t iova = buf_vec[0].buf_iova;
720 uint16_t hdr_vec_idx = 0;
723 len = RTE_MIN(remain,
724 buf_vec[hdr_vec_idx].buf_len);
725 dst = buf_vec[hdr_vec_idx].buf_addr;
726 rte_memcpy((void *)(uintptr_t)dst,
727 (void *)(uintptr_t)src,
730 PRINT_PACKET(dev, (uintptr_t)dst,
732 vhost_log_cache_write(dev, vq,
741 PRINT_PACKET(dev, (uintptr_t)hdr_addr,
743 vhost_log_cache_write(dev, vq,
751 cpy_len = RTE_MIN(buf_avail, mbuf_avail);
753 if (likely(cpy_len > MAX_BATCH_LEN ||
754 vq->batch_copy_nb_elems >= vq->size)) {
755 rte_memcpy((void *)((uintptr_t)(buf_addr + buf_offset)),
756 rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
758 vhost_log_cache_write(dev, vq, buf_iova + buf_offset,
760 PRINT_PACKET(dev, (uintptr_t)(buf_addr + buf_offset),
763 batch_copy[vq->batch_copy_nb_elems].dst =
764 (void *)((uintptr_t)(buf_addr + buf_offset));
765 batch_copy[vq->batch_copy_nb_elems].src =
766 rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
767 batch_copy[vq->batch_copy_nb_elems].log_addr =
768 buf_iova + buf_offset;
769 batch_copy[vq->batch_copy_nb_elems].len = cpy_len;
770 vq->batch_copy_nb_elems++;
773 mbuf_avail -= cpy_len;
774 mbuf_offset += cpy_len;
775 buf_avail -= cpy_len;
776 buf_offset += cpy_len;
784 static __rte_always_inline uint32_t
785 virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
786 struct rte_mbuf **pkts, uint32_t count)
788 uint32_t pkt_idx = 0;
789 uint16_t num_buffers;
790 struct buf_vector buf_vec[BUF_VECTOR_MAX];
793 rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
794 avail_head = *((volatile uint16_t *)&vq->avail->idx);
796 for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
797 uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
800 if (unlikely(reserve_avail_buf_split(dev, vq,
801 pkt_len, buf_vec, &num_buffers,
802 avail_head, &nr_vec) < 0)) {
803 VHOST_LOG_DEBUG(VHOST_DATA,
804 "(%d) failed to get enough desc from vring\n",
806 vq->shadow_used_idx -= num_buffers;
810 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
812 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
813 dev->vid, vq->last_avail_idx,
814 vq->last_avail_idx + num_buffers);
816 if (copy_mbuf_to_desc(dev, vq, pkts[pkt_idx],
819 vq->shadow_used_idx -= num_buffers;
823 vq->last_avail_idx += num_buffers;
826 do_data_copy_enqueue(dev, vq);
828 if (likely(vq->shadow_used_idx)) {
829 flush_shadow_used_ring_split(dev, vq);
830 vhost_vring_call_split(dev, vq);
836 static __rte_always_inline uint32_t
837 virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
838 struct rte_mbuf **pkts, uint32_t count)
840 uint32_t pkt_idx = 0;
841 uint16_t num_buffers;
842 struct buf_vector buf_vec[BUF_VECTOR_MAX];
844 for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
845 uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
847 uint16_t nr_descs = 0;
849 if (unlikely(reserve_avail_buf_packed(dev, vq,
850 pkt_len, buf_vec, &nr_vec,
851 &num_buffers, &nr_descs) < 0)) {
852 VHOST_LOG_DEBUG(VHOST_DATA,
853 "(%d) failed to get enough desc from vring\n",
855 vq->shadow_used_idx -= num_buffers;
859 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
861 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
862 dev->vid, vq->last_avail_idx,
863 vq->last_avail_idx + num_buffers);
865 if (copy_mbuf_to_desc(dev, vq, pkts[pkt_idx],
868 vq->shadow_used_idx -= num_buffers;
872 vq->last_avail_idx += nr_descs;
873 if (vq->last_avail_idx >= vq->size) {
874 vq->last_avail_idx -= vq->size;
875 vq->avail_wrap_counter ^= 1;
879 do_data_copy_enqueue(dev, vq);
881 if (likely(vq->shadow_used_idx)) {
882 flush_shadow_used_ring_packed(dev, vq);
883 vhost_vring_call_packed(dev, vq);
889 static __rte_always_inline uint32_t
890 virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
891 struct rte_mbuf **pkts, uint32_t count)
893 struct vhost_virtqueue *vq;
895 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
896 if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
897 RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
898 dev->vid, __func__, queue_id);
902 vq = dev->virtqueue[queue_id];
904 rte_spinlock_lock(&vq->access_lock);
906 if (unlikely(vq->enabled == 0))
907 goto out_access_unlock;
909 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
910 vhost_user_iotlb_rd_lock(vq);
912 if (unlikely(vq->access_ok == 0))
913 if (unlikely(vring_translate(dev, vq) < 0))
916 count = RTE_MIN((uint32_t)MAX_PKT_BURST, count);
920 if (vq_is_packed(dev))
921 count = virtio_dev_rx_packed(dev, vq, pkts, count);
923 count = virtio_dev_rx_split(dev, vq, pkts, count);
926 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
927 vhost_user_iotlb_rd_unlock(vq);
930 rte_spinlock_unlock(&vq->access_lock);
936 rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
937 struct rte_mbuf **pkts, uint16_t count)
939 struct virtio_net *dev = get_device(vid);
944 if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
945 RTE_LOG(ERR, VHOST_DATA,
946 "(%d) %s: built-in vhost net backend is disabled.\n",
951 return virtio_dev_rx(dev, queue_id, pkts, count);
955 virtio_net_with_host_offload(struct virtio_net *dev)
958 ((1ULL << VIRTIO_NET_F_CSUM) |
959 (1ULL << VIRTIO_NET_F_HOST_ECN) |
960 (1ULL << VIRTIO_NET_F_HOST_TSO4) |
961 (1ULL << VIRTIO_NET_F_HOST_TSO6) |
962 (1ULL << VIRTIO_NET_F_HOST_UFO)))
969 parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
971 struct ipv4_hdr *ipv4_hdr;
972 struct ipv6_hdr *ipv6_hdr;
974 struct ether_hdr *eth_hdr;
977 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
979 m->l2_len = sizeof(struct ether_hdr);
980 ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
982 if (ethertype == ETHER_TYPE_VLAN) {
983 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
985 m->l2_len += sizeof(struct vlan_hdr);
986 ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
989 l3_hdr = (char *)eth_hdr + m->l2_len;
992 case ETHER_TYPE_IPv4:
994 *l4_proto = ipv4_hdr->next_proto_id;
995 m->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
996 *l4_hdr = (char *)l3_hdr + m->l3_len;
997 m->ol_flags |= PKT_TX_IPV4;
999 case ETHER_TYPE_IPv6:
1001 *l4_proto = ipv6_hdr->proto;
1002 m->l3_len = sizeof(struct ipv6_hdr);
1003 *l4_hdr = (char *)l3_hdr + m->l3_len;
1004 m->ol_flags |= PKT_TX_IPV6;
1014 static __rte_always_inline void
1015 vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
1017 uint16_t l4_proto = 0;
1018 void *l4_hdr = NULL;
1019 struct tcp_hdr *tcp_hdr = NULL;
1021 if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
1024 parse_ethernet(m, &l4_proto, &l4_hdr);
1025 if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
1026 if (hdr->csum_start == (m->l2_len + m->l3_len)) {
1027 switch (hdr->csum_offset) {
1028 case (offsetof(struct tcp_hdr, cksum)):
1029 if (l4_proto == IPPROTO_TCP)
1030 m->ol_flags |= PKT_TX_TCP_CKSUM;
1032 case (offsetof(struct udp_hdr, dgram_cksum)):
1033 if (l4_proto == IPPROTO_UDP)
1034 m->ol_flags |= PKT_TX_UDP_CKSUM;
1036 case (offsetof(struct sctp_hdr, cksum)):
1037 if (l4_proto == IPPROTO_SCTP)
1038 m->ol_flags |= PKT_TX_SCTP_CKSUM;
1046 if (l4_hdr && hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
1047 switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
1048 case VIRTIO_NET_HDR_GSO_TCPV4:
1049 case VIRTIO_NET_HDR_GSO_TCPV6:
1051 m->ol_flags |= PKT_TX_TCP_SEG;
1052 m->tso_segsz = hdr->gso_size;
1053 m->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
1055 case VIRTIO_NET_HDR_GSO_UDP:
1056 m->ol_flags |= PKT_TX_UDP_SEG;
1057 m->tso_segsz = hdr->gso_size;
1058 m->l4_len = sizeof(struct udp_hdr);
1061 RTE_LOG(WARNING, VHOST_DATA,
1062 "unsupported gso type %u.\n", hdr->gso_type);
1068 static __rte_always_inline void
1069 put_zmbuf(struct zcopy_mbuf *zmbuf)
1074 static __rte_always_inline int
1075 copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
1076 struct buf_vector *buf_vec, uint16_t nr_vec,
1077 struct rte_mbuf *m, struct rte_mempool *mbuf_pool)
1079 uint32_t buf_avail, buf_offset;
1080 uint64_t buf_addr, buf_iova, buf_len;
1081 uint32_t mbuf_avail, mbuf_offset;
1083 struct rte_mbuf *cur = m, *prev = m;
1084 struct virtio_net_hdr tmp_hdr;
1085 struct virtio_net_hdr *hdr = NULL;
1086 /* A counter to avoid desc dead loop chain */
1087 uint16_t vec_idx = 0;
1088 struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
1091 buf_addr = buf_vec[vec_idx].buf_addr;
1092 buf_iova = buf_vec[vec_idx].buf_iova;
1093 buf_len = buf_vec[vec_idx].buf_len;
1095 if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) {
1100 if (likely(nr_vec > 1))
1101 rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
1103 if (virtio_net_with_host_offload(dev)) {
1104 if (unlikely(buf_len < sizeof(struct virtio_net_hdr))) {
1106 uint64_t remain = sizeof(struct virtio_net_hdr);
1108 uint64_t dst = (uint64_t)(uintptr_t)&tmp_hdr;
1109 uint16_t hdr_vec_idx = 0;
1112 * No luck, the virtio-net header doesn't fit
1113 * in a contiguous virtual area.
1116 len = RTE_MIN(remain,
1117 buf_vec[hdr_vec_idx].buf_len);
1118 src = buf_vec[hdr_vec_idx].buf_addr;
1119 rte_memcpy((void *)(uintptr_t)dst,
1120 (void *)(uintptr_t)src, len);
1129 hdr = (struct virtio_net_hdr *)((uintptr_t)buf_addr);
1135 * A virtio driver normally uses at least 2 desc buffers
1136 * for Tx: the first for storing the header, and others
1137 * for storing the data.
1139 if (unlikely(buf_len < dev->vhost_hlen)) {
1140 buf_offset = dev->vhost_hlen - buf_len;
1142 buf_addr = buf_vec[vec_idx].buf_addr;
1143 buf_iova = buf_vec[vec_idx].buf_iova;
1144 buf_len = buf_vec[vec_idx].buf_len;
1145 buf_avail = buf_len - buf_offset;
1146 } else if (buf_len == dev->vhost_hlen) {
1147 if (unlikely(++vec_idx >= nr_vec))
1149 buf_addr = buf_vec[vec_idx].buf_addr;
1150 buf_iova = buf_vec[vec_idx].buf_iova;
1151 buf_len = buf_vec[vec_idx].buf_len;
1154 buf_avail = buf_len;
1156 buf_offset = dev->vhost_hlen;
1157 buf_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
1160 rte_prefetch0((void *)(uintptr_t)
1161 (buf_addr + buf_offset));
1164 (uintptr_t)(buf_addr + buf_offset),
1165 (uint32_t)buf_avail, 0);
1168 mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
1172 cpy_len = RTE_MIN(buf_avail, mbuf_avail);
1175 * A desc buf might across two host physical pages that are
1176 * not continuous. In such case (gpa_to_hpa returns 0), data
1177 * will be copied even though zero copy is enabled.
1179 if (unlikely(dev->dequeue_zero_copy && (hpa = gpa_to_hpa(dev,
1180 buf_iova + buf_offset, cpy_len)))) {
1181 cur->data_len = cpy_len;
1184 (void *)(uintptr_t)(buf_addr + buf_offset);
1185 cur->buf_iova = hpa;
1188 * In zero copy mode, one mbuf can only reference data
1189 * for one or partial of one desc buff.
1191 mbuf_avail = cpy_len;
1193 if (likely(cpy_len > MAX_BATCH_LEN ||
1194 vq->batch_copy_nb_elems >= vq->size ||
1195 (hdr && cur == m))) {
1196 rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *,
1198 (void *)((uintptr_t)(buf_addr +
1202 batch_copy[vq->batch_copy_nb_elems].dst =
1203 rte_pktmbuf_mtod_offset(cur, void *,
1205 batch_copy[vq->batch_copy_nb_elems].src =
1206 (void *)((uintptr_t)(buf_addr +
1208 batch_copy[vq->batch_copy_nb_elems].len =
1210 vq->batch_copy_nb_elems++;
1214 mbuf_avail -= cpy_len;
1215 mbuf_offset += cpy_len;
1216 buf_avail -= cpy_len;
1217 buf_offset += cpy_len;
1219 /* This buf reaches to its end, get the next one */
1220 if (buf_avail == 0) {
1221 if (++vec_idx >= nr_vec)
1224 buf_addr = buf_vec[vec_idx].buf_addr;
1225 buf_iova = buf_vec[vec_idx].buf_iova;
1226 buf_len = buf_vec[vec_idx].buf_len;
1229 * Prefecth desc n + 1 buffer while
1230 * desc n buffer is processed.
1232 if (vec_idx + 1 < nr_vec)
1233 rte_prefetch0((void *)(uintptr_t)
1234 buf_vec[vec_idx + 1].buf_addr);
1237 buf_avail = buf_len;
1239 PRINT_PACKET(dev, (uintptr_t)buf_addr,
1240 (uint32_t)buf_avail, 0);
1244 * This mbuf reaches to its end, get a new one
1245 * to hold more data.
1247 if (mbuf_avail == 0) {
1248 cur = rte_pktmbuf_alloc(mbuf_pool);
1249 if (unlikely(cur == NULL)) {
1250 RTE_LOG(ERR, VHOST_DATA, "Failed to "
1251 "allocate memory for mbuf.\n");
1255 if (unlikely(dev->dequeue_zero_copy))
1256 rte_mbuf_refcnt_update(cur, 1);
1259 prev->data_len = mbuf_offset;
1261 m->pkt_len += mbuf_offset;
1265 mbuf_avail = cur->buf_len - RTE_PKTMBUF_HEADROOM;
1269 prev->data_len = mbuf_offset;
1270 m->pkt_len += mbuf_offset;
1273 vhost_dequeue_offload(hdr, m);
1280 static __rte_always_inline struct zcopy_mbuf *
1281 get_zmbuf(struct vhost_virtqueue *vq)
1287 /* search [last_zmbuf_idx, zmbuf_size) */
1288 i = vq->last_zmbuf_idx;
1289 last = vq->zmbuf_size;
1292 for (; i < last; i++) {
1293 if (vq->zmbufs[i].in_use == 0) {
1294 vq->last_zmbuf_idx = i + 1;
1295 vq->zmbufs[i].in_use = 1;
1296 return &vq->zmbufs[i];
1302 /* search [0, last_zmbuf_idx) */
1304 last = vq->last_zmbuf_idx;
1311 static __rte_always_inline bool
1312 mbuf_is_consumed(struct rte_mbuf *m)
1315 if (rte_mbuf_refcnt_read(m) > 1)
1323 static __rte_always_inline void
1324 restore_mbuf(struct rte_mbuf *m)
1326 uint32_t mbuf_size, priv_size;
1329 priv_size = rte_pktmbuf_priv_size(m->pool);
1330 mbuf_size = sizeof(struct rte_mbuf) + priv_size;
1331 /* start of buffer is after mbuf structure and priv data */
1333 m->buf_addr = (char *)m + mbuf_size;
1334 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
1339 static __rte_always_inline uint16_t
1340 virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
1341 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1344 uint16_t free_entries;
1346 if (unlikely(dev->dequeue_zero_copy)) {
1347 struct zcopy_mbuf *zmbuf, *next;
1350 for (zmbuf = TAILQ_FIRST(&vq->zmbuf_list);
1351 zmbuf != NULL; zmbuf = next) {
1352 next = TAILQ_NEXT(zmbuf, next);
1354 if (mbuf_is_consumed(zmbuf->mbuf)) {
1355 update_shadow_used_ring_split(vq,
1356 zmbuf->desc_idx, 0);
1359 TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
1360 restore_mbuf(zmbuf->mbuf);
1361 rte_pktmbuf_free(zmbuf->mbuf);
1367 flush_shadow_used_ring_split(dev, vq);
1368 vhost_vring_call_split(dev, vq);
1371 rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
1373 free_entries = *((volatile uint16_t *)&vq->avail->idx) -
1375 if (free_entries == 0)
1378 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
1380 count = RTE_MIN(count, MAX_PKT_BURST);
1381 count = RTE_MIN(count, free_entries);
1382 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
1385 for (i = 0; i < count; i++) {
1386 struct buf_vector buf_vec[BUF_VECTOR_MAX];
1387 uint16_t head_idx, dummy_len;
1388 uint16_t nr_vec = 0;
1391 if (unlikely(fill_vec_buf_split(dev, vq,
1392 vq->last_avail_idx + i,
1394 &head_idx, &dummy_len,
1395 VHOST_ACCESS_RO) < 0))
1398 if (likely(dev->dequeue_zero_copy == 0))
1399 update_shadow_used_ring_split(vq, head_idx, 0);
1401 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
1403 pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
1404 if (unlikely(pkts[i] == NULL)) {
1405 RTE_LOG(ERR, VHOST_DATA,
1406 "Failed to allocate memory for mbuf.\n");
1410 err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i],
1412 if (unlikely(err)) {
1413 rte_pktmbuf_free(pkts[i]);
1417 if (unlikely(dev->dequeue_zero_copy)) {
1418 struct zcopy_mbuf *zmbuf;
1420 zmbuf = get_zmbuf(vq);
1422 rte_pktmbuf_free(pkts[i]);
1425 zmbuf->mbuf = pkts[i];
1426 zmbuf->desc_idx = head_idx;
1429 * Pin lock the mbuf; we will check later to see
1430 * whether the mbuf is freed (when we are the last
1431 * user) or not. If that's the case, we then could
1432 * update the used ring safely.
1434 rte_mbuf_refcnt_update(pkts[i], 1);
1437 TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
1440 vq->last_avail_idx += i;
1442 if (likely(dev->dequeue_zero_copy == 0)) {
1443 do_data_copy_dequeue(vq);
1444 if (unlikely(i < count))
1445 vq->shadow_used_idx = i;
1446 flush_shadow_used_ring_split(dev, vq);
1447 vhost_vring_call_split(dev, vq);
1453 static __rte_always_inline uint16_t
1454 virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
1455 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1459 rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]);
1461 if (unlikely(dev->dequeue_zero_copy)) {
1462 struct zcopy_mbuf *zmbuf, *next;
1464 for (zmbuf = TAILQ_FIRST(&vq->zmbuf_list);
1465 zmbuf != NULL; zmbuf = next) {
1466 next = TAILQ_NEXT(zmbuf, next);
1468 if (mbuf_is_consumed(zmbuf->mbuf)) {
1469 update_shadow_used_ring_packed(vq,
1474 TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
1475 restore_mbuf(zmbuf->mbuf);
1476 rte_pktmbuf_free(zmbuf->mbuf);
1482 flush_shadow_used_ring_packed(dev, vq);
1483 vhost_vring_call_packed(dev, vq);
1486 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
1488 count = RTE_MIN(count, MAX_PKT_BURST);
1489 VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
1492 for (i = 0; i < count; i++) {
1493 struct buf_vector buf_vec[BUF_VECTOR_MAX];
1494 uint16_t buf_id, dummy_len;
1495 uint16_t desc_count, nr_vec = 0;
1498 if (unlikely(fill_vec_buf_packed(dev, vq,
1499 vq->last_avail_idx, &desc_count,
1501 &buf_id, &dummy_len,
1502 VHOST_ACCESS_RW) < 0))
1505 if (likely(dev->dequeue_zero_copy == 0))
1506 update_shadow_used_ring_packed(vq, buf_id, 0,
1509 rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
1511 pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
1512 if (unlikely(pkts[i] == NULL)) {
1513 RTE_LOG(ERR, VHOST_DATA,
1514 "Failed to allocate memory for mbuf.\n");
1518 err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i],
1520 if (unlikely(err)) {
1521 rte_pktmbuf_free(pkts[i]);
1525 if (unlikely(dev->dequeue_zero_copy)) {
1526 struct zcopy_mbuf *zmbuf;
1528 zmbuf = get_zmbuf(vq);
1530 rte_pktmbuf_free(pkts[i]);
1533 zmbuf->mbuf = pkts[i];
1534 zmbuf->desc_idx = buf_id;
1535 zmbuf->desc_count = desc_count;
1538 * Pin lock the mbuf; we will check later to see
1539 * whether the mbuf is freed (when we are the last
1540 * user) or not. If that's the case, we then could
1541 * update the used ring safely.
1543 rte_mbuf_refcnt_update(pkts[i], 1);
1546 TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
1549 vq->last_avail_idx += desc_count;
1550 if (vq->last_avail_idx >= vq->size) {
1551 vq->last_avail_idx -= vq->size;
1552 vq->avail_wrap_counter ^= 1;
1556 if (likely(dev->dequeue_zero_copy == 0)) {
1557 do_data_copy_dequeue(vq);
1558 if (unlikely(i < count))
1559 vq->shadow_used_idx = i;
1560 flush_shadow_used_ring_packed(dev, vq);
1561 vhost_vring_call_packed(dev, vq);
1568 rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
1569 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
1571 struct virtio_net *dev;
1572 struct rte_mbuf *rarp_mbuf = NULL;
1573 struct vhost_virtqueue *vq;
1575 dev = get_device(vid);
1579 if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
1580 RTE_LOG(ERR, VHOST_DATA,
1581 "(%d) %s: built-in vhost net backend is disabled.\n",
1582 dev->vid, __func__);
1586 if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) {
1587 RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
1588 dev->vid, __func__, queue_id);
1592 vq = dev->virtqueue[queue_id];
1594 if (unlikely(rte_spinlock_trylock(&vq->access_lock) == 0))
1597 if (unlikely(vq->enabled == 0))
1598 goto out_access_unlock;
1600 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
1601 vhost_user_iotlb_rd_lock(vq);
1603 if (unlikely(vq->access_ok == 0))
1604 if (unlikely(vring_translate(dev, vq) < 0))
1608 * Construct a RARP broadcast packet, and inject it to the "pkts"
1609 * array, to looks like that guest actually send such packet.
1611 * Check user_send_rarp() for more information.
1613 * broadcast_rarp shares a cacheline in the virtio_net structure
1614 * with some fields that are accessed during enqueue and
1615 * rte_atomic16_cmpset() causes a write if using cmpxchg. This could
1616 * result in false sharing between enqueue and dequeue.
1618 * Prevent unnecessary false sharing by reading broadcast_rarp first
1619 * and only performing cmpset if the read indicates it is likely to
1622 if (unlikely(rte_atomic16_read(&dev->broadcast_rarp) &&
1623 rte_atomic16_cmpset((volatile uint16_t *)
1624 &dev->broadcast_rarp.cnt, 1, 0))) {
1626 rarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);
1627 if (rarp_mbuf == NULL) {
1628 RTE_LOG(ERR, VHOST_DATA,
1629 "Failed to make RARP packet.\n");
1635 if (vq_is_packed(dev))
1636 count = virtio_dev_tx_packed(dev, vq, mbuf_pool, pkts, count);
1638 count = virtio_dev_tx_split(dev, vq, mbuf_pool, pkts, count);
1641 if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
1642 vhost_user_iotlb_rd_unlock(vq);
1645 rte_spinlock_unlock(&vq->access_lock);
1647 if (unlikely(rarp_mbuf != NULL)) {
1649 * Inject it to the head of "pkts" array, so that switch's mac
1650 * learning table will get updated first.
1652 memmove(&pkts[1], pkts, count * sizeof(struct rte_mbuf *));
1653 pkts[0] = rarp_mbuf;