DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tiwei Bie <tiwei.bie@intel.com>
To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/4] net/virtio-user: fix the control vq support
Date: Wed, 23 Jan 2019 01:01:41 +0800	[thread overview]
Message-ID: <20190122170143.5650-3-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190122170143.5650-1-tiwei.bie@intel.com>

This patch fixed below issues in the packed ring based control
vq support in virtio user:

1. The idx_hdr should be used_idx instead of the id in the desc;
2. We just need to write out a single used descriptor for each
   descriptor list;
3. The avail/used bits should be initialized to 0;

Meanwhile, make the function name consistent with other parts.

Fixes: 48a4464029a7 ("net/virtio-user: support control VQ for packed")

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c            | 11 ++++++
 .../net/virtio/virtio_user/virtio_user_dev.c  | 37 +++++++++++--------
 drivers/net/virtio/virtio_user_ethdev.c       |  7 +---
 3 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index a3fe65599..7c4c1df00 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -224,6 +224,17 @@ virtio_send_command_packed(struct virtnet_ctl *cvq,
 		vq->used_wrap_counter ^= 1;
 	}
 
+	PMD_INIT_LOG(DEBUG, "vq->vq_free_cnt=%d\n"
+			"vq->vq_avail_idx=%d\n"
+			"vq->vq_used_cons_idx=%d\n"
+			"vq->avail_wrap_counter=%d\n"
+			"vq->used_wrap_counter=%d\n",
+			vq->vq_free_cnt,
+			vq->vq_avail_idx,
+			vq->vq_used_cons_idx,
+			vq->avail_wrap_counter,
+			vq->used_wrap_counter);
+
 	result = cvq->virtio_net_hdr_mz->addr;
 	return result;
 }
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index c1919177d..89d287a74 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -632,9 +632,9 @@ desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
 }
 
 static uint32_t
-virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
-			    struct vring_packed *vring,
-			    uint16_t idx_hdr)
+virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
+				   struct vring_packed *vring,
+				   uint16_t idx_hdr)
 {
 	struct virtio_net_ctrl_hdr *hdr;
 	virtio_net_ctrl_ack status = ~0;
@@ -671,6 +671,10 @@ virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
 	*(virtio_net_ctrl_ack *)(uintptr_t)
 		vring->desc_packed[idx_status].addr = status;
 
+	/* Update used descriptor */
+	vring->desc_packed[idx_hdr].id = vring->desc_packed[idx_status].id;
+	vring->desc_packed[idx_hdr].len = sizeof(status);
+
 	return n_descs;
 }
 
@@ -679,24 +683,25 @@ virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
 {
 	struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
 	struct vring_packed *vring = &dev->packed_vrings[queue_idx];
-	uint16_t id, n_descs;
+	uint16_t n_descs;
 
 	while (desc_is_avail(&vring->desc_packed[vq->used_idx],
 			     vq->used_wrap_counter)) {
-		id = vring->desc_packed[vq->used_idx].id;
 
-		n_descs = virtio_user_handle_ctrl_msg_pq(dev, vring, id);
+		n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
+				vq->used_idx);
 
-		do {
-			vring->desc_packed[vq->used_idx].flags =
-				VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
-				VRING_DESC_F_USED(vq->used_wrap_counter);
-			if (++vq->used_idx >= dev->queue_size) {
-				vq->used_idx -= dev->queue_size;
-				vq->used_wrap_counter ^= 1;
-			}
-			n_descs--;
-		} while (n_descs);
+		rte_smp_wmb();
+		vring->desc_packed[vq->used_idx].flags =
+			VRING_DESC_F_WRITE |
+			VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
+			VRING_DESC_F_USED(vq->used_wrap_counter);
+
+		vq->used_idx += n_descs;
+		if (vq->used_idx >= dev->queue_size) {
+			vq->used_idx -= dev->queue_size;
+			vq->used_wrap_counter ^= 1;
+		}
 	}
 }
 
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index c01f45cab..6423e1f61 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -274,7 +274,6 @@ virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
 static void
 virtio_user_setup_queue_packed(struct virtqueue *vq,
 			       struct virtio_user_dev *dev)
-
 {
 	uint16_t queue_idx = vq->vq_queue_index;
 	struct vring_packed *vring;
@@ -300,10 +299,8 @@ virtio_user_setup_queue_packed(struct virtqueue *vq,
 	dev->packed_queues[queue_idx].avail_wrap_counter = true;
 	dev->packed_queues[queue_idx].used_wrap_counter = true;
 
-	for (i = 0; i < vring->num; i++) {
-		vring->desc_packed[i].flags = VRING_DESC_F_USED(1) |
-					      VRING_DESC_F_AVAIL(1);
-	}
+	for (i = 0; i < vring->num; i++)
+		vring->desc_packed[i].flags = 0;
 }
 
 static void
-- 
2.17.1

  parent reply	other threads:[~2019-01-22 17:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-22 17:01 [dpdk-dev] [PATCH 0/4] Virtio fixes Tiwei Bie
2019-01-22 17:01 ` [dpdk-dev] [PATCH 1/4] net/virtio: fix the control vq support Tiwei Bie
     [not found]   ` <CGME20190123130903eucas1p2730776e71039a79024dd7602b5dcad7d@eucas1p2.samsung.com>
2019-01-23 13:09     ` [dpdk-dev] [1/4] " Ilya Maximets
     [not found]       ` <CGME20190123163323eucas1p1baaec2c637cdc656ab9b26dbfd455bae@eucas1p1.samsung.com>
2019-01-23 16:33         ` Ilya Maximets
2019-01-23 22:02           ` Maxime Coquelin
2019-01-23 22:03   ` [dpdk-dev] [PATCH 1/4] " Maxime Coquelin
2019-01-22 17:01 ` Tiwei Bie [this message]
2019-01-23 22:07   ` [dpdk-dev] [PATCH 2/4] net/virtio-user: " Maxime Coquelin
2019-01-22 17:01 ` [dpdk-dev] [PATCH 3/4] net/virtio: use virtio barrier in packed ring Tiwei Bie
     [not found]   ` <CGME20190123155232eucas1p28bdd3a5c220452b81e21e48c19f3e5a7@eucas1p2.samsung.com>
2019-01-23 15:52     ` [dpdk-dev] [3/4] " Ilya Maximets
2019-01-23 22:09   ` [dpdk-dev] [PATCH 3/4] " Maxime Coquelin
2019-01-22 17:01 ` [dpdk-dev] [PATCH 4/4] net/virtio-user: fix used ring update in cvq handling Tiwei Bie
2019-01-23 22:08   ` Maxime Coquelin
2019-01-23 22:25 ` [dpdk-dev] [PATCH 0/4] Virtio fixes Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190122170143.5650-3-tiwei.bie@intel.com \
    --to=tiwei.bie@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).