diff mbox series

[v3,3/4] virtio-net: Init queues after features negotiation

Message ID 20191120235801.4928-4-aik@ozlabs.ru
State Superseded
Headers show
Series virtio: Enable iommu_platform=on | expand

Commit Message

Alexey Kardashevskiy Nov. 20, 2019, 11:58 p.m. UTC
Every virtio device negotiates virtio protocol features before setting
up internal queue descriptors with one exception which is virtio-net.

This moves virtio_queue_init_vq() later to have feature negotiation
happened sooner. This is going to be used for IOMMU setup later.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 lib/libvirtio/virtio-net.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

Comments

Michael Roth Dec. 4, 2019, 12:12 a.m. UTC | #1
Quoting Alexey Kardashevskiy (2019-11-20 17:58:00)
> Every virtio device negotiates virtio protocol features before setting
> up internal queue descriptors with one exception which is virtio-net.
> 
> This moves virtio_queue_init_vq() later to have feature negotiation
> happened sooner. This is going to be used for IOMMU setup later.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  lib/libvirtio/virtio-net.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c
> index 2290b2d74765..ae67883020ef 100644
> --- a/lib/libvirtio/virtio-net.c
> +++ b/lib/libvirtio/virtio-net.c
> @@ -84,18 +84,6 @@ static int virtionet_init_pci(struct virtio_net *vnet, struct virtio_device *dev
>         /* Reset device */
>         virtio_reset_device(vdev);
> 
> -       /* The queue information can be retrieved via the virtio header that
> -        * can be found in the I/O BAR. First queue is the receive queue,
> -        * second the transmit queue, and the forth is the control queue for
> -        * networking options.
> -        * We are only interested in the receive and transmit queue here. */
> -       if (!virtio_queue_init_vq(vdev, VQ_RX) ||
> -           !virtio_queue_init_vq(vdev, VQ_TX)) {
> -               virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER
> -                                 |VIRTIO_STAT_FAILED);
> -               return -1;
> -       }
> -
>         /* Acknowledge device. */
>         virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE);
> 
> @@ -113,7 +101,7 @@ static int virtionet_init(struct virtio_net *vnet)
>         int status = VIRTIO_STAT_ACKNOWLEDGE | VIRTIO_STAT_DRIVER;
>         struct virtio_device *vdev = &vnet->vdev;
>         net_driver_t *driver = &vnet->driver;
> -       struct vqs *vq_tx = &vdev->vq[VQ_TX], *vq_rx = &vdev->vq[VQ_RX];
> +       struct vqs *vq_tx, *vq_rx;
> 
>         dprintf("virtionet_init(%02x:%02x:%02x:%02x:%02x:%02x)\n",
>                 driver->mac_addr[0], driver->mac_addr[1],
> @@ -137,6 +125,19 @@ static int virtionet_init(struct virtio_net *vnet)
>                 virtio_set_guest_features(vdev,  0);
>         }
> 
> +       /* The queue information can be retrieved via the virtio header that
> +        * can be found in the I/O BAR. First queue is the receive queue,
> +        * second the transmit queue, and the forth is the control queue for
> +        * networking options.
> +        * We are only interested in the receive and transmit queue here. */
> +       vq_rx = virtio_queue_init_vq(vdev, VQ_RX);
> +       vq_tx = virtio_queue_init_vq(vdev, VQ_TX);
> +       if (!vq_rx || !vq_tx) {
> +               virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER
> +                                 |VIRTIO_STAT_FAILED);
> +               return -1;
> +       }
> +
>         /* Allocate memory for one transmit an multiple receive buffers */
>         vq_rx->buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size)
>                                    * RX_QUEUE_SIZE);
> -- 
> 2.17.1
> 
> _______________________________________________
> SLOF mailing list
> SLOF@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/slof
diff mbox series

Patch

diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c
index 2290b2d74765..ae67883020ef 100644
--- a/lib/libvirtio/virtio-net.c
+++ b/lib/libvirtio/virtio-net.c
@@ -84,18 +84,6 @@  static int virtionet_init_pci(struct virtio_net *vnet, struct virtio_device *dev
 	/* Reset device */
 	virtio_reset_device(vdev);
 
-	/* The queue information can be retrieved via the virtio header that
-	 * can be found in the I/O BAR. First queue is the receive queue,
-	 * second the transmit queue, and the forth is the control queue for
-	 * networking options.
-	 * We are only interested in the receive and transmit queue here. */
-	if (!virtio_queue_init_vq(vdev, VQ_RX) ||
-	    !virtio_queue_init_vq(vdev, VQ_TX)) {
-		virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER
-				  |VIRTIO_STAT_FAILED);
-		return -1;
-	}
-
 	/* Acknowledge device. */
 	virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE);
 
@@ -113,7 +101,7 @@  static int virtionet_init(struct virtio_net *vnet)
 	int status = VIRTIO_STAT_ACKNOWLEDGE | VIRTIO_STAT_DRIVER;
 	struct virtio_device *vdev = &vnet->vdev;
 	net_driver_t *driver = &vnet->driver;
-	struct vqs *vq_tx = &vdev->vq[VQ_TX], *vq_rx = &vdev->vq[VQ_RX];
+	struct vqs *vq_tx, *vq_rx;
 
 	dprintf("virtionet_init(%02x:%02x:%02x:%02x:%02x:%02x)\n",
 		driver->mac_addr[0], driver->mac_addr[1],
@@ -137,6 +125,19 @@  static int virtionet_init(struct virtio_net *vnet)
 		virtio_set_guest_features(vdev,  0);
 	}
 
+	/* The queue information can be retrieved via the virtio header that
+	 * can be found in the I/O BAR. First queue is the receive queue,
+	 * second the transmit queue, and the forth is the control queue for
+	 * networking options.
+	 * We are only interested in the receive and transmit queue here. */
+	vq_rx = virtio_queue_init_vq(vdev, VQ_RX);
+	vq_tx = virtio_queue_init_vq(vdev, VQ_TX);
+	if (!vq_rx || !vq_tx) {
+		virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER
+				  |VIRTIO_STAT_FAILED);
+		return -1;
+	}
+
 	/* Allocate memory for one transmit an multiple receive buffers */
 	vq_rx->buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size)
 				   * RX_QUEUE_SIZE);