From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 9E2B337B1 for ; Fri, 29 Apr 2016 02:48:47 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 28 Apr 2016 17:48:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,549,1455004800"; d="scan'208";a="794650059" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by orsmga003.jf.intel.com with ESMTP; 28 Apr 2016 17:48:46 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: huawei.xie@intel.com, yuanhan.liu@linux.intel.com, Jianfeng Tan Date: Fri, 29 Apr 2016 00:48:45 +0000 Message-Id: <1461890926-16727-2-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461890926-16727-1-git-send-email-jianfeng.tan@intel.com> References: <1461673932-128879-1-git-send-email-jianfeng.tan@intel.com> <1461890926-16727-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v3 1/2] virtio: cleanup virtio_dev_queue_setup() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2016 00:48:48 -0000 Signed-off-by: Jianfeng Tan --- drivers/net/virtio/virtio_ethdev.c | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 1fe90ae..b3f4158 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -285,6 +285,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, unsigned int vq_size, size; struct virtio_hw *hw = dev->data->dev_private; struct virtqueue *vq = NULL; + const char *queue_names[] = {"rvq", "txq", "cvq"}; PMD_INIT_LOG(DEBUG, "setting up queue: %u", vtpci_queue_idx); @@ -304,34 +305,34 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, return -EINVAL; } - if (queue_type == VTNET_RQ) { - snprintf(vq_name, sizeof(vq_name), "port%d_rvq%d", - dev->data->port_id, queue_idx); - vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) + - vq_size * sizeof(struct vq_desc_extra), RTE_CACHE_LINE_SIZE); - vq->sw_ring = rte_zmalloc_socket("rxq->sw_ring", - (RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) * - sizeof(vq->sw_ring[0]), RTE_CACHE_LINE_SIZE, socket_id); - } else if (queue_type == VTNET_TQ) { - snprintf(vq_name, sizeof(vq_name), "port%d_tvq%d", - dev->data->port_id, queue_idx); - vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) + - vq_size * sizeof(struct vq_desc_extra), RTE_CACHE_LINE_SIZE); - } else if (queue_type == VTNET_CQ) { - snprintf(vq_name, sizeof(vq_name), "port%d_cvq", - dev->data->port_id); - vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) + - vq_size * sizeof(struct vq_desc_extra), - RTE_CACHE_LINE_SIZE); + if (queue_type < VTNET_RQ || queue_type > VTNET_CQ) { + PMD_INIT_LOG(ERR, "invalid queue type: %d", queue_type); + return -EINVAL; } + + snprintf(vq_name, sizeof(vq_name), "port%d_%s%d", + dev->data->port_id, queue_names[queue_type], queue_idx); + vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) + + vq_size * sizeof(struct vq_desc_extra), + RTE_CACHE_LINE_SIZE); if (vq == NULL) { PMD_INIT_LOG(ERR, "Can not allocate virtqueue"); return -ENOMEM; } - if (queue_type == VTNET_RQ && vq->sw_ring == NULL) { - PMD_INIT_LOG(ERR, "Can not allocate RX soft ring"); - rte_free(vq); - return -ENOMEM; + + if (queue_type == VTNET_RQ) { + size_t sz_sw; + + sz_sw = (RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) * + sizeof(vq->sw_ring[0]); + vq->sw_ring = rte_zmalloc_socket("rxq->sw_ring", sz_sw, + RTE_CACHE_LINE_SIZE, + socket_id); + if (!vq->sw_ring) { + PMD_INIT_LOG(ERR, "Can not allocate RX soft ring"); + rte_free(vq); + return -ENOMEM; + } } vq->hw = hw; -- 2.1.4