From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH 2/6] ethdev: add common function for reserving DMA regions Date: Thu, 22 Oct 2015 23:34:46 -0700 Message-ID: <1445582090-5927-3-git-send-email-stephen@networkplumber.org> References: <1445582090-5927-1-git-send-email-stephen@networkplumber.org> To: dev@dpdk.org Return-path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id 31D0FC460 for ; Fri, 23 Oct 2015 08:34:46 +0200 (CEST) Received: by pasz6 with SMTP id z6so109392689pas.2 for ; Thu, 22 Oct 2015 23:34:45 -0700 (PDT) In-Reply-To: <1445582090-5927-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" The code to create aligned DMA regions was copy-n-pasted throughout all the drivers. Since this code has to change now create a common function that just does the right thing for Xen at runtime. Signed-off-by: Stephen Hemminger --- lib/librte_ether/rte_ethdev.c | 24 ++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index f593f6e..6c520a3 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -2838,6 +2838,30 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data) return 0; } + +const struct rte_memzone * +rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, + uint16_t queue_id, size_t size, unsigned align, + int socket_id) +{ + char z_name[RTE_MEMZONE_NAMESIZE]; + const struct rte_memzone *mz; + + snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d", + dev->driver->pci_drv.name, ring_name, + dev->data->port_id, queue_id); + + mz = rte_memzone_lookup(z_name); + if (mz) + return mz; + + if (is_xen_dom0_supported()) + return rte_memzone_reserve_bounded(z_name, size, socket_id, + 0, align, RTE_PGSIZE_2M); + else + return rte_memzone_reserve_aligned(z_name, size, socket_id, + 0, align); +} int rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id, diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 8a8c82b..8d2098d 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -3598,6 +3598,29 @@ extern int rte_eth_timesync_read_rx_timestamp(uint8_t port_id, extern int rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp); +/** + * Create memzone for HW rings. + * malloc can't be used as the physical address is needed. + * If the memzone is already created, then this function returns a ptr + * to the old one. + * + * @param eth_dev + * The *eth_dev* pointer is the address of the *rte_eth_dev* structure + * @param name + * The name of the memory zone + * @param queue_id + * The index of the queue to add to name + * @param size + * The sizeof of the memory area + * @param align + * Alignment for resulting memzone. Must be a power of 2. + * @param socket_id + * The *socket_id* argument is the socket identifier in case of NUMA. + */ +const struct rte_memzone * +rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name, + uint16_t queue_id, size_t size, + unsigned align, int socket_id); #ifdef __cplusplus } #endif -- 2.1.4