From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3EDD443729;
	Tue, 19 Dec 2023 12:00:48 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id C4062402DE;
	Tue, 19 Dec 2023 12:00:47 +0100 (CET)
Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com
 [67.231.156.173])
 by mails.dpdk.org (Postfix) with ESMTP id 1FF3C40283
 for <dev@dpdk.org>; Tue, 19 Dec 2023 12:00:47 +0100 (CET)
Received: from pps.filterd (m0045851.ppops.net [127.0.0.1])
 by mx0b-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id
 3BJ9nu6X003244; Tue, 19 Dec 2023 03:00:46 -0800
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=
 from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-type; s=pfpt0220; bh=bed/6eB/6jf84LF6ylqdr
 D8EcQfVuVSaLlOSIMEvzPI=; b=YI02UQFnC0/xoz37pmbqGoJhh6j1Sev19AUMx
 sBejhx33Eq6tfk5rfaJyHXVu8oJp2sDlVZM7v+vPejIXH2dJHUd7r1aAjGw6zVvG
 WDfBx5umHrzrpHLejdkZJ5Dte6G8pq3L4R7BrUNc5COcH505gQbl+2tOVz+b86Gz
 zRLXDir0BNCaYtgDsquvkEVaUIAGdZnyMXa+q/uYwQeQaxmPOrvSmu09jfZrgzim
 MbTw8w3cB345xfrdNk6F/2Q1l11ulnPW7zejnzmRUui6Tg4XwKnCTqnEVgHtgmj4
 KqC/yVUKhQoMngaKkJkzqSmxd16IjxCQLpU0qKIEec2mC6sfA==
Received: from dc5-exch02.marvell.com ([199.233.59.182])
 by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3v1c9kt334-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);
 Tue, 19 Dec 2023 03:00:46 -0800 (PST)
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com
 (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48;
 Tue, 19 Dec 2023 03:00:44 -0800
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend
 Transport; Tue, 19 Dec 2023 03:00:44 -0800
Received: from localhost.localdomain (unknown [10.28.36.178])
 by maili.marvell.com (Postfix) with ESMTP id 118913F7092;
 Tue, 19 Dec 2023 03:00:40 -0800 (PST)
From: Amit Prakash Shukla <amitprakashs@marvell.com>
To: Chengwen Feng <fengchengwen@huawei.com>, Kevin Laatz
 <kevin.laatz@intel.com>, Bruce Richardson <bruce.richardson@intel.com>
CC: <dev@dpdk.org>, <jerinj@marvell.com>, <vattunuru@marvell.com>,
 <ndabilpuram@marvell.com>, <anoobj@marvell.com>,
 <mb@smartsharesystems.com>, Amit Prakash Shukla <amitprakashs@marvell.com>
Subject: [PATCH v2] lib/dmadev: get DMA device using device ID
Date: Tue, 19 Dec 2023 16:30:27 +0530
Message-ID: <20231219110027.16443-1-amitprakashs@marvell.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20231208075526.2696553-1-amitprakashs@marvell.com>
References: <20231208075526.2696553-1-amitprakashs@marvell.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Proofpoint-ORIG-GUID: OxHiBroAqYL44CJJp5v7Rk8_QE-k8PNu
X-Proofpoint-GUID: OxHiBroAqYL44CJJp5v7Rk8_QE-k8PNu
X-Proofpoint-Virus-Version: vendor=baseguard
 engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26
 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

DMA library has a function to get DMA device based on device name but
there is no function to get DMA device using device id.

Added a function that lookup for the dma device using device id and
returns the pointer to the same.

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
v2:
  - Arranged api in alphabetical order in version.map

 lib/dmadev/rte_dmadev.c     |  9 +++++++++
 lib/dmadev/rte_dmadev_pmd.h | 14 ++++++++++++++
 lib/dmadev/version.map      |  1 +
 3 files changed, 24 insertions(+)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 4e5e420c82..83f49e77f2 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -397,6 +397,15 @@ rte_dma_is_valid(int16_t dev_id)
 		rte_dma_devices[dev_id].state != RTE_DMA_DEV_UNUSED;
 }
 
+struct rte_dma_dev *
+rte_dma_pmd_get_dev_by_id(const int dev_id)
+{
+	if (!rte_dma_is_valid(dev_id))
+		return NULL;
+
+	return &rte_dma_devices[dev_id];
+}
+
 uint16_t
 rte_dma_count_avail(void)
 {
diff --git a/lib/dmadev/rte_dmadev_pmd.h b/lib/dmadev/rte_dmadev_pmd.h
index c61cedfb23..f68c3ac6aa 100644
--- a/lib/dmadev/rte_dmadev_pmd.h
+++ b/lib/dmadev/rte_dmadev_pmd.h
@@ -167,6 +167,20 @@ struct rte_dma_dev *rte_dma_pmd_allocate(const char *name, int numa_node,
 __rte_internal
 int rte_dma_pmd_release(const char *name);
 
+/**
+ * @internal
+ * Get the rte_dma_dev structure device pointer for the device id.
+ *
+ * @param dev_id
+ *   Device ID value to select the device structure.
+ *
+ * @return
+ *   - rte_dma_dev structure pointer for the given device ID on success, NULL
+ *   otherwise.
+ */
+__rte_internal
+struct rte_dma_dev *rte_dma_pmd_get_dev_by_id(const int dev_id);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map
index 2a3736514c..046dbfa988 100644
--- a/lib/dmadev/version.map
+++ b/lib/dmadev/version.map
@@ -25,6 +25,7 @@ INTERNAL {
 
 	rte_dma_fp_objs;
 	rte_dma_pmd_allocate;
+	rte_dma_pmd_get_dev_by_id;
 	rte_dma_pmd_release;
 
 	local: *;
-- 
2.17.1