virtio: fix ring size negotiation
authorStephen Hemminger <shemming@brocade.com>
Thu, 11 Jun 2015 15:53:27 +0000 (08:53 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 12 Jun 2015 12:44:59 +0000 (14:44 +0200)
Negotiate the virtio ring size. The host may allow for very large
rings but application may only want a smaller ring.
Conversely, if the number of descriptors requested exceeds the virtio
host queue size, then just silently use the smaller host size.

This fixes issues with virtio in non-QEMU envirionments.
For example Google Compute Engine allows up to 16K elements
in ring.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
drivers/net/virtio/virtio_ethdev.c

index b18e541..a71aaa0 100644 (file)
@@ -267,13 +267,21 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
        if (vq_size == 0) {
                PMD_INIT_LOG(ERR, "%s: virtqueue does not exist", __func__);
                return -EINVAL;
-       } else if (!rte_is_power_of_2(vq_size)) {
+       }
+
+       if (!rte_is_power_of_2(vq_size)) {
                PMD_INIT_LOG(ERR, "%s: virtqueue size is not powerof 2", __func__);
                return -EINVAL;
-       } else if (nb_desc != vq_size) {
-               PMD_INIT_LOG(ERR, "Warning: nb_desc(%d) is not equal to vq size (%d), fall to vq size",
-                       nb_desc, vq_size);
-               nb_desc = vq_size;
+       }
+
+       if (nb_desc < vq_size) {
+               if (!rte_is_power_of_2(nb_desc)) {
+                       PMD_INIT_LOG(ERR,
+                                    "nb_desc(%u) size is not powerof 2",
+                                    nb_desc);
+                       return -EINVAL;
+               }
+               vq_size = nb_desc;
        }
 
        if (queue_type == VTNET_RQ) {