From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id CC30C5A44 for ; Wed, 24 Oct 2018 16:33:06 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DFDB80464; Wed, 24 Oct 2018 14:33:06 +0000 (UTC) Received: from localhost (ovpn-117-63.ams2.redhat.com [10.36.117.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 968E310018FD; Wed, 24 Oct 2018 14:33:00 +0000 (UTC) From: Jens Freimann To: dev@dpdk.org Cc: tiwei.bie@intel.com, maxime.coquelin@redhat.com Date: Wed, 24 Oct 2018 16:32:31 +0200 Message-Id: <20181024143236.21271-4-jfreimann@redhat.com> In-Reply-To: <20181024143236.21271-1-jfreimann@redhat.com> References: <20181024143236.21271-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 24 Oct 2018 14:33:06 +0000 (UTC) Subject: [dpdk-dev] [PATCH v9 3/8] net/virtio: add packed virtqueue helpers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 14:33:07 -0000 Add helper functions to set/clear and check descriptor flags. Signed-off-by: Jens Freimann --- drivers/net/virtio/virtio_ring.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h index f84ab5e34..629d3477a 100644 --- a/drivers/net/virtio/virtio_ring.h +++ b/drivers/net/virtio/virtio_ring.h @@ -77,6 +77,8 @@ struct vring_packed_desc_event { struct vring { unsigned int num; + unsigned int avail_wrap_counter; + unsigned int used_wrap_counter; union { struct vring_desc_packed *desc_packed; struct vring_desc *desc; @@ -91,6 +93,30 @@ struct vring { }; }; +static inline void +_set_desc_avail(struct vring_desc_packed *desc, int wrap_counter) +{ + desc->flags |= VRING_DESC_F_AVAIL(wrap_counter) | + VRING_DESC_F_USED(!wrap_counter); +} + +static inline void +set_desc_avail(struct vring *vr, struct vring_desc_packed *desc) +{ + _set_desc_avail(desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used(struct vring_desc_packed *desc, struct vring *vr) +{ + uint16_t used, flags; + + flags = desc->flags; + used = !!(flags & VRING_DESC_F_USED(1)); + + return used == vr->used_wrap_counter; +} + /* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. * -- 2.17.1