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 9A0796936 for ; Mon, 30 May 2016 12:55:56 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP; 30 May 2016 03:55:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,389,1459839600"; d="scan'208";a="112799667" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by fmsmga004.fm.intel.com with ESMTP; 30 May 2016 03:55:54 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: Jianfeng Tan , Huawei Xie , rich.lane@bigswitch.com, yuanhan.liu@linux.intel.com, mst@redhat.com, nakajima.yoshihiro@lab.ntt.co.jp, p.fedin@samsung.com, ann.zhuangyanying@huawei.com, mukawa@igel.co.jp, nhorman@tuxdriver.com Date: Mon, 30 May 2016 10:55:33 +0000 Message-Id: <1464605739-140761-3-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464605739-140761-1-git-send-email-jianfeng.tan@intel.com> References: <1446748276-132087-1-git-send-email-jianfeng.tan@intel.com> <1464605739-140761-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v5 2/8] virtio: clean up 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: Mon, 30 May 2016 10:55:57 -0000 Abstract vring hdr desc init as an inline method. Signed-off-by: Huawei Xie Signed-off-by: Jianfeng Tan --- drivers/net/virtio/virtio_ethdev.c | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index a3031e4..781886d 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -278,6 +278,26 @@ virtio_dev_queue_release(struct virtqueue *vq) } } +static void +vring_hdr_desc_init(struct virtqueue *vq) +{ + int i; + struct virtio_tx_region *txr = vq->virtio_net_hdr_mz->addr; + + for (i = 0; i < vq->vq_nentries; i++) { + struct vring_desc *start_dp = txr[i].tx_indir; + + vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir)); + + /* first indirect descriptor is always the tx header */ + start_dp->addr = vq->virtio_net_hdr_mem + i * sizeof(*txr) + + offsetof(struct virtio_tx_region, tx_hdr); + + start_dp->len = vq->hw->vtnet_hdr_size; + start_dp->flags = VRING_DESC_F_NEXT; + } +} + int virtio_dev_queue_setup(struct rte_eth_dev *dev, int queue_type, uint16_t queue_idx, @@ -375,8 +395,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, if (queue_type == VTNET_TQ) { const struct rte_memzone *hdr_mz; - struct virtio_tx_region *txr; - unsigned int i; + size_t hdr_mz_sz = vq_size * sizeof(struct virtio_tx_region); /* * For each xmit packet, allocate a virtio_net_hdr @@ -385,7 +404,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, snprintf(vq_name, sizeof(vq_name), "port%d_tvq%d_hdrzone", dev->data->port_id, queue_idx); hdr_mz = rte_memzone_reserve_aligned(vq_name, - vq_size * sizeof(*txr), + hdr_mz_sz, socket_id, 0, RTE_CACHE_LINE_SIZE); if (hdr_mz == NULL) { @@ -399,21 +418,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq->virtio_net_hdr_mz = hdr_mz; vq->virtio_net_hdr_mem = hdr_mz->phys_addr; - txr = hdr_mz->addr; - memset(txr, 0, vq_size * sizeof(*txr)); - for (i = 0; i < vq_size; i++) { - struct vring_desc *start_dp = txr[i].tx_indir; - - vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir)); - - /* first indirect descriptor is always the tx header */ - start_dp->addr = vq->virtio_net_hdr_mem - + i * sizeof(*txr) - + offsetof(struct virtio_tx_region, tx_hdr); - - start_dp->len = vq->hw->vtnet_hdr_size; - start_dp->flags = VRING_DESC_F_NEXT; - } + memset(hdr_mz->addr, 0, hdr_mz_sz); + vring_hdr_desc_init(vq); } else if (queue_type == VTNET_CQ) { /* Allocate a page for control vq command, data and status */ -- 2.1.4