Add helper functions to set/clear and check descriptor flags.

Signed-off-by: Jens Freimann <jfreim...@redhat.com>
---
 drivers/net/virtio/virtio_ring.h | 32 ++++++++++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.c   |  3 +++
 2 files changed, 35 insertions(+)

diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h
index 839359444..47df96aac 100644
--- a/drivers/net/virtio/virtio_ring.h
+++ b/drivers/net/virtio/virtio_ring.h
@@ -74,12 +74,44 @@ struct vring_desc_1_1 {
 
 struct vring {
        unsigned int num;
+       unsigned int avail_wrap_counter;
        struct vring_desc  *desc;
        struct vring_avail *avail;
        struct vring_used  *used;
        struct vring_desc_1_1 *desc_1_1;
 };
 
+static inline void toggle_wrap_counter(struct vring *vr)
+{
+       vr->avail_wrap_counter ^= 1;
+}
+
+static inline void _set_desc_avail(struct vring_desc_1_1 *desc,
+                                  int wrap_counter)
+{
+       uint16_t flags = desc->flags;
+
+       if (wrap_counter) {
+               flags |= DESC_AVAIL;
+               flags &= ~DESC_USED;
+       } else {
+               flags &= ~DESC_AVAIL;
+               flags |= DESC_USED;
+       }
+
+       desc->flags = flags;
+}
+
+static inline void set_desc_avail(struct vring *vr, struct vring_desc_1_1 
*desc)
+{
+       _set_desc_avail(desc, vr->avail_wrap_counter);
+}
+
+static inline int desc_is_used(struct vring_desc_1_1 *desc)
+{
+       return !(desc->flags & DESC_AVAIL) == !(desc->flags & DESC_USED);
+}
+
 /* The standard layout for the ring is a continuous chunk of memory which
  * looks like this.  We assume num is a power of 2.
  *
diff --git a/drivers/net/virtio/virtqueue.c b/drivers/net/virtio/virtqueue.c
index 1ada4fe08..052444756 100644
--- a/drivers/net/virtio/virtqueue.c
+++ b/drivers/net/virtio/virtqueue.c
@@ -43,6 +43,9 @@ virtqueue_rxvq_flush(struct virtqueue *vq)
        uint16_t used_idx, desc_idx;
        uint16_t nb_used, i;
 
+       if (vtpci_packed_queue(vq->hw))
+               return;
+
        nb_used = VIRTQUEUE_NUSED(vq);
 
        for (i = 0; i < nb_used; i++) {
-- 
2.14.3

Reply via email to