1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
9 #include "virtio_logs.h"
10 #include "virtio_pci.h"
13 * Two types of mbuf to be cleaned:
14 * 1) mbuf that has been consumed by backend but not used by virtio.
15 * 2) mbuf that hasn't been consued by backend.
18 virtqueue_detatch_unused(struct virtqueue *vq)
20 struct rte_mbuf *cookie;
24 for (idx = 0; idx < vq->vq_nentries; idx++) {
25 cookie = vq->vq_descx[idx].cookie;
27 vq->vq_descx[idx].cookie = NULL;
34 /* Flush the elements in the used ring. */
36 virtqueue_flush(struct virtqueue *vq)
38 struct vring_used_elem *uep;
39 struct vq_desc_extra *dxp;
40 uint16_t used_idx, desc_idx;
43 nb_used = VIRTQUEUE_NUSED(vq);
45 for (i = 0; i < nb_used; i++) {
46 used_idx = vq->vq_used_cons_idx & (vq->vq_nentries - 1);
47 uep = &vq->vq_ring.used->ring[used_idx];
48 desc_idx = (uint16_t)uep->id;
49 dxp = &vq->vq_descx[desc_idx];
50 if (dxp->cookie != NULL) {
51 rte_pktmbuf_free(dxp->cookie);
54 vq->vq_used_cons_idx++;
55 vq_ring_free_chain(vq, desc_idx);