From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH 5/5] virtio: fix ring size negotiation Date: Thu, 11 Jun 2015 08:53:27 -0700 Message-ID: <1434038007-8964-6-git-send-email-stephen@networkplumber.org> References: <1434038007-8964-1-git-send-email-stephen@networkplumber.org> Cc: dev@dpdk.org, Stephen Hemminger To: changchun.ouyang@intel.com Return-path: Received: from mail-qc0-f171.google.com (mail-qc0-f171.google.com [209.85.216.171]) by dpdk.org (Postfix) with ESMTP id 04C29C310 for ; Thu, 11 Jun 2015 17:53:35 +0200 (CEST) Received: by qcnj1 with SMTP id j1so3251797qcn.0 for ; Thu, 11 Jun 2015 08:53:34 -0700 (PDT) In-Reply-To: <1434038007-8964-1-git-send-email-stephen@networkplumber.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stephen Hemminger Negotate 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 --- drivers/net/virtio/virtio_ethdev.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 2afa371..befd0bc 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -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) { -- 2.1.4