[v1,17/21] net/virtio-user: send shadow virtqueue info to the backend

Message ID 20221130155639.150553-18-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Add control queue & MQ support to Virtio-user vDPA |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Nov. 30, 2022, 3:56 p.m. UTC
  This patch adds sending the shadow control queue info
to the backend.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 28 ++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
  

Comments

Chenbo Xia Jan. 31, 2023, 5:22 a.m. UTC | #1
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Wednesday, November 30, 2022 11:57 PM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>;
> david.marchand@redhat.com; eperezma@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [PATCH v1 17/21] net/virtio-user: send shadow virtqueue info to
> the backend
> 
> This patch adds sending the shadow control queue info
> to the backend.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  .../net/virtio/virtio_user/virtio_user_dev.c  | 28 ++++++++++++++++---
>  1 file changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 16a0e07413..1a5386a3f6 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -66,6 +66,18 @@ virtio_user_kick_queue(struct virtio_user_dev *dev,
> uint32_t queue_sel)
>  		.flags = 0, /* disable log */
>  	};
> 
> +	if (queue_sel == dev->max_queue_pairs * 2) {
> +		if (!dev->scvq) {
> +			PMD_INIT_LOG(ERR, "(%s) Shadow control queue expected
> but missing",
> +					dev->path);
> +			goto err;
> +		}
> +
> +		/* Use shadow control queue information */
> +		vring = &dev->scvq->vq_split.ring;
> +		pq_vring = &dev->scvq->vq_packed.ring;
> +	}
> +
>  	if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
>  		addr.desc_user_addr =
>  			(uint64_t)(uintptr_t)pq_vring->desc;
> @@ -118,9 +130,13 @@ static int
>  virtio_user_queue_setup(struct virtio_user_dev *dev,
>  			int (*fn)(struct virtio_user_dev *, uint32_t))
>  {
> -	uint32_t i;
> +	uint32_t i, nr_vq;
> 
> -	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
> +	nr_vq = dev->max_queue_pairs * 2;
> +	if (dev->hw_cvq)
> +		nr_vq++;
> +
> +	for (i = 0; i < nr_vq; i++) {
>  		if (fn(dev, i) < 0) {
>  			PMD_DRV_LOG(ERR, "(%s) setup VQ %u failed", dev->path,
> i);
>  			return -1;
> @@ -381,11 +397,15 @@ virtio_user_dev_init_mac(struct virtio_user_dev *dev,
> const char *mac)
>  static int
>  virtio_user_dev_init_notify(struct virtio_user_dev *dev)
>  {
> -	uint32_t i, j;
> +	uint32_t i, j, nr_vq;
>  	int callfd;
>  	int kickfd;
> 
> -	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
> +	nr_vq = dev->max_queue_pairs * 2;
> +	if (dev->hw_cvq)
> +		nr_vq++;
> +
> +	for (i = 0; i < nr_vq; i++) {
>  		/* May use invalid flag, but some backend uses kickfd and
>  		 * callfd as criteria to judge if dev is alive. so finally we
>  		 * use real event_fd.
> --
> 2.38.1

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 16a0e07413..1a5386a3f6 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -66,6 +66,18 @@  virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 		.flags = 0, /* disable log */
 	};
 
+	if (queue_sel == dev->max_queue_pairs * 2) {
+		if (!dev->scvq) {
+			PMD_INIT_LOG(ERR, "(%s) Shadow control queue expected but missing",
+					dev->path);
+			goto err;
+		}
+
+		/* Use shadow control queue information */
+		vring = &dev->scvq->vq_split.ring;
+		pq_vring = &dev->scvq->vq_packed.ring;
+	}
+
 	if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
 		addr.desc_user_addr =
 			(uint64_t)(uintptr_t)pq_vring->desc;
@@ -118,9 +130,13 @@  static int
 virtio_user_queue_setup(struct virtio_user_dev *dev,
 			int (*fn)(struct virtio_user_dev *, uint32_t))
 {
-	uint32_t i;
+	uint32_t i, nr_vq;
 
-	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
+	nr_vq = dev->max_queue_pairs * 2;
+	if (dev->hw_cvq)
+		nr_vq++;
+
+	for (i = 0; i < nr_vq; i++) {
 		if (fn(dev, i) < 0) {
 			PMD_DRV_LOG(ERR, "(%s) setup VQ %u failed", dev->path, i);
 			return -1;
@@ -381,11 +397,15 @@  virtio_user_dev_init_mac(struct virtio_user_dev *dev, const char *mac)
 static int
 virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 {
-	uint32_t i, j;
+	uint32_t i, j, nr_vq;
 	int callfd;
 	int kickfd;
 
-	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
+	nr_vq = dev->max_queue_pairs * 2;
+	if (dev->hw_cvq)
+		nr_vq++;
+
+	for (i = 0; i < nr_vq; i++) {
 		/* May use invalid flag, but some backend uses kickfd and
 		 * callfd as criteria to judge if dev is alive. so finally we
 		 * use real event_fd.