From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A3774A0C55; Wed, 13 Oct 2021 17:18:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0041841208; Wed, 13 Oct 2021 17:18:10 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 4DBA1411F7 for ; Wed, 13 Oct 2021 17:18:05 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10136"; a="290944076" X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="290944076" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 08:18:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="441682098" Received: from silpixa00399126.ir.intel.com ([10.237.223.151]) by orsmga006.jf.intel.com with ESMTP; 13 Oct 2021 08:17:58 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: conor.walsh@intel.com, kevin.laatz@intel.com, fengchengwen@huawei.com, jerinj@marvell.com, Bruce Richardson Date: Wed, 13 Oct 2021 16:17:28 +0100 Message-Id: <20211013151736.762378-6-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211013151736.762378-1-bruce.richardson@intel.com> References: <20210924102942.2878051-1-bruce.richardson@intel.com> <20211013151736.762378-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v7 05/13] dmadev: add device iterator X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a function and wrapper macro to iterate over all dma devices. Signed-off-by: Bruce Richardson Reviewed-by: Conor Walsh Reviewed-by: Kevin Laatz --- lib/dmadev/rte_dmadev.c | 13 +++++++++++++ lib/dmadev/rte_dmadev.h | 18 ++++++++++++++++++ lib/dmadev/version.map | 1 + 3 files changed, 32 insertions(+) diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c index c737cc6cdc..b6647e6ff8 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -49,6 +49,19 @@ rte_dma_dev_max(size_t dev_max) return 0; } +int16_t +rte_dma_next_dev(int16_t start_dev_id) +{ + int16_t dev_id = start_dev_id; + while (dev_id < dma_devices_max && rte_dma_devices[dev_id].state == RTE_DMA_DEV_UNUSED) + dev_id++; + + if (dev_id < dma_devices_max) + return dev_id; + + return -1; +} + static int dma_check_name(const char *name) { diff --git a/lib/dmadev/rte_dmadev.h b/lib/dmadev/rte_dmadev.h index a0824be20d..bf78748b0c 100644 --- a/lib/dmadev/rte_dmadev.h +++ b/lib/dmadev/rte_dmadev.h @@ -220,6 +220,24 @@ bool rte_dma_is_valid(int16_t dev_id); __rte_experimental uint16_t rte_dma_count_avail(void); +/** + * Iterates over valid dmadev instances. + * + * @param start_dev_id + * The id of the next possible dmadev. + * @return + * Next valid dmadev, UINT16_MAX if there is none. + */ +__rte_experimental +int16_t rte_dma_next_dev(int16_t start_dev_id); + +/** Utility macro to iterate over all available dmadevs */ +#define RTE_DMA_FOREACH_DEV(p) \ + for (p = rte_dma_next_dev(0); \ + p != -1; \ + p = rte_dma_next_dev(p + 1)) + + /**@{@name DMA capability * @see struct rte_dma_info::dev_capa */ diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map index 4bbfdd52f6..ef561acd46 100644 --- a/lib/dmadev/version.map +++ b/lib/dmadev/version.map @@ -15,6 +15,7 @@ EXPERIMENTAL { rte_dma_get_dev_id_by_name; rte_dma_info_get; rte_dma_is_valid; + rte_dma_next_dev; rte_dma_start; rte_dma_stats_get; rte_dma_stats_reset; -- 2.30.2