]> git.droids-corp.org - dpdk.git/commitdiff
virtio: fix queue size and number of descriptors
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 20 Jul 2015 18:40:45 +0000 (11:40 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 22 Jul 2015 08:33:50 +0000 (10:33 +0200)
The virtual queue ring size and the number of slots actually usable
are separate parameters. In the most common environment (QEMU)
the virtual queue ring size is 256, but some environments the
ring maybe much larger.

The ring size comes from the host and the driver must use the
actual size passed.

The number of descriptors can be either zero to use the whole
available ring, or some value smaller. This is used to limit
the number of mbufs allocated for the receive ring. If more
descriptors are requested than available the size is silently
truncated.

Note: the ring size (from host) must be a power of two, but
the number of descriptors used can be any size from 1 to the
size of the virtual ring.

Fixes: d78deadae4dc ("virtio: fix ring size negotiation")
Reported-by: Changchun Ouyang <changchun.ouyang@intel.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
drivers/net/virtio/virtio_ethdev.c

index 9ca9bb265b708c218365b7d057d54ecc637f15de..d460d894a76df43dcf31fb3e3d7e0ad1e793e430 100644 (file)
@@ -276,8 +276,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
         */
        vq_size = VIRTIO_READ_REG_2(hw, VIRTIO_PCI_QUEUE_NUM);
        PMD_INIT_LOG(DEBUG, "vq_size: %d nb_desc:%d", vq_size, nb_desc);
-       if (nb_desc == 0)
-               nb_desc = vq_size;
        if (vq_size == 0) {
                PMD_INIT_LOG(ERR, "%s: virtqueue does not exist", __func__);
                return -EINVAL;
@@ -288,16 +286,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
                return -EINVAL;
        }
 
-       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) {
                snprintf(vq_name, sizeof(vq_name), "port%d_rvq%d",
                        dev->data->port_id, queue_idx);
@@ -325,7 +313,10 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
        vq->queue_id = queue_idx;
        vq->vq_queue_index = vtpci_queue_idx;
        vq->vq_nentries = vq_size;
-       vq->vq_free_cnt = vq_size;
+
+       if (nb_desc == 0 || nb_desc > vq_size)
+               nb_desc = vq_size;
+       vq->vq_free_cnt = nb_desc;
 
        /*
         * Reserve a memzone for vring elements