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 83C995690 for ; Fri, 29 Apr 2016 03:18:41 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 28 Apr 2016 18:18:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,549,1455004800"; d="scan'208";a="694039298" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by FMSMGA003.fm.intel.com with ESMTP; 28 Apr 2016 18:18:39 -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, michael.qiu@intel.com, ann.zhuangyanying@huawei.com, mukawa@igel.co.jp, nhorman@tuxdriver.com Date: Fri, 29 Apr 2016 01:18:30 +0000 Message-Id: <1461892716-19122-3-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461892716-19122-1-git-send-email-jianfeng.tan@intel.com> References: <1446748276-132087-1-git-send-email-jianfeng.tan@intel.com> <1461892716-19122-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v4 2/8] virtio: abstract vring hdr desc init as a method 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 01:18:42 -0000 To make it reusable, here we abstract the initialization of vring header into a method. Signed-off-by: Huawei Xie Signed-off-by: Jianfeng Tan Acked-By: Neil Horman --- drivers/net/virtio/virtio_ethdev.c | 22 ++++------------------ drivers/net/virtio/virtqueue.h | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 534f0e6..0c20fb9 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -380,8 +380,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 @@ -390,7 +389,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) { @@ -404,21 +403,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 */ diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 83d89ca..3b19fd1 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -264,6 +264,26 @@ vring_desc_init(struct vring_desc *dp, uint16_t n) dp[i].next = VQ_RING_DESC_CHAIN_END; } +static inline 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; + } +} + /** * Tell the backend not to interrupt us. */ -- 2.1.4