From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jens Freimann Subject: [PATCH 11/14] vhost: add helpers for packed virtqueues Date: Mon, 29 Jan 2018 15:11:40 +0100 Message-ID: <20180129141143.13437-12-jfreimann@redhat.com> References: <20180129141143.13437-1-jfreimann@redhat.com> Cc: tiwei.bie@intel.com, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mst@redhat.com To: dev@dpdk.org Return-path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id DEF801B7C9 for ; Mon, 29 Jan 2018 15:13:10 +0100 (CET) In-Reply-To: <20180129141143.13437-1-jfreimann@redhat.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add some helper functions to set/check descriptor flags and toggle the used wrap counter. Signed-off-by: Jens Freimann --- lib/librte_vhost/virtio-1.1.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/librte_vhost/virtio-1.1.h b/lib/librte_vhost/virtio-1.1.h index 5ca0bc33f..84039797e 100644 --- a/lib/librte_vhost/virtio-1.1.h +++ b/lib/librte_vhost/virtio-1.1.h @@ -17,4 +17,47 @@ struct vring_desc_1_1 { uint16_t flags; }; +static inline void +toggle_wrap_counter(struct vhost_virtqueue *vq) +{ + vq->used_wrap_counter ^= 1; +} + +static inline int +desc_is_avail(struct vhost_virtqueue *vq, struct vring_desc_1_1 *desc) +{ + if (!vq) + return -1; + + if (vq->used_wrap_counter == 1) + if ((desc->flags & DESC_AVAIL) && !(desc->flags & DESC_USED)) + return 1; + if (vq->used_wrap_counter == 0) + if (!(desc->flags & DESC_AVAIL) && (desc->flags & DESC_USED)) + return 1; + return 0; +} + +static inline void +_set_desc_used(struct vring_desc_1_1 *desc, int wrap_counter) +{ + uint16_t flags = desc->flags; + + if (wrap_counter == 1) { + flags |= DESC_USED; + flags |= DESC_AVAIL; + } else { + flags &= ~DESC_USED; + flags &= ~DESC_AVAIL; + } + + desc->flags = flags; +} + +static inline void +set_desc_used(struct vhost_virtqueue *vq, struct vring_desc_1_1 *desc) +{ + _set_desc_used(desc, vq->used_wrap_counter); +} + #endif /* __VIRTIO_1_1_H */ -- 2.14.3