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 6160745BFE;
	Mon, 28 Oct 2024 12:02:33 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 4DE4C40E2A;
	Mon, 28 Oct 2024 12:02:33 +0100 (CET)
Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com
 [67.231.148.174])
 by mails.dpdk.org (Postfix) with ESMTP id 40CB340E41
 for <dev@dpdk.org>; Mon, 28 Oct 2024 12:01:52 +0100 (CET)
Received: from pps.filterd (m0045849.ppops.net [127.0.0.1])
 by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49SA0lhE010719;
 Mon, 28 Oct 2024 04:01:50 -0700
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=
 cc:content-transfer-encoding:content-type:date:from:in-reply-to
 :message-id:mime-version:references:subject:to; s=pfpt0220; bh=N
 98gnfCqZSBU08Wn7YY4UaMXywS6UVFLX7VTk/mE4ag=; b=Wlzsq+0V70y21GU6F
 gfzoj56cy83YjC3W5iWwHJmecG5G//s0QqWmzqsKY4HNLqq6r0Jmdf7lsGG+r8Wu
 OUv6tLwAcOrem0K4UcjoPtnxczVk/WeSp9eMUulIdL2AEjHYmVD25WbdbgtZLHar
 FBD2dwgTuNGuw+4q21BrgDvWlEFbFrIhHDc/kEuy6sIXtJAfW8X3AtYpePNpOw6X
 7j+CSoWFIA/8/pgoKQ3qMMEKbgx+CDykqCADKb9YmSnxnWtZ3op/Q+TUqLAOmo/Y
 6iQtUz+2XCmraRwmKosLKYNAugA1zaLd4yY7aZR8WrJPBdaRuKrN0DGNys4Zdcnb
 r5bNA==
Received: from dc5-exch05.marvell.com ([199.233.59.128])
 by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42j7v2055q-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
 Mon, 28 Oct 2024 04:01:49 -0700 (PDT)
Received: from DC5-EXCH05.marvell.com (10.69.176.209) by
 DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.1544.4; Mon, 28 Oct 2024 04:01:48 -0700
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com
 (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend
 Transport; Mon, 28 Oct 2024 04:01:48 -0700
Received: from localhost.localdomain (unknown [10.28.36.102])
 by maili.marvell.com (Postfix) with ESMTP id F2B935C68E6;
 Mon, 28 Oct 2024 04:01:45 -0700 (PDT)
From: Akhil Goyal <gakhil@marvell.com>
To: <dev@dpdk.org>
CC: <thomas@monjalon.net>, <david.marchand@redhat.com>,
 <hemant.agrawal@nxp.com>, <jerinj@marvell.com>, <hkalra@marvell.com>,
 <stephen@networkplumber.org>, <sachin.saxena@oss.nxp.com>,
 <ferruh.yigit@amd.com>, Akhil Goyal <gakhil@marvell.com>
Subject: [PATCH v6 8/9] raw/cnxk_rvu_lf: support getting BAR addresses
Date: Mon, 28 Oct 2024 16:31:14 +0530
Message-ID: <20241028110115.1070655-9-gakhil@marvell.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20241028110115.1070655-1-gakhil@marvell.com>
References: <20241024131759.3337333-1-gakhil@marvell.com>
 <20241028110115.1070655-1-gakhil@marvell.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Proofpoint-GUID: ISeche-fAicB9VYPO0AfdOyCIGMYAmQ-
X-Proofpoint-ORIG-GUID: ISeche-fAicB9VYPO0AfdOyCIGMYAmQ-
X-Proofpoint-Virus-Version: vendor=baseguard
 engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29
 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01
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

Added rte_pmd_rvu_lf_bar_get() API to get BAR address
for out of tree drivers to configure hardware.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 doc/guides/rawdevs/cnxk_rvu_lf.rst           |  8 +++++++
 drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c        | 24 ++++++++++++++++++++
 drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf_driver.h | 18 +++++++++++++++
 drivers/raw/cnxk_rvu_lf/version.map          |  1 +
 4 files changed, 51 insertions(+)

diff --git a/doc/guides/rawdevs/cnxk_rvu_lf.rst b/doc/guides/rawdevs/cnxk_rvu_lf.rst
index 0854c88ac9..708c9410fd 100644
--- a/doc/guides/rawdevs/cnxk_rvu_lf.rst
+++ b/doc/guides/rawdevs/cnxk_rvu_lf.rst
@@ -22,6 +22,7 @@ The RVU LF device implements following features in the rawdev API:
 - Register/unregister mailbox callbacks for the other side to process mailboxes.
 - Set mailbox message ID range to be used by the driver.
 - Process mailbox messages.
+- Get BAR Addresses for the out of tree drivers to configure registers.
 
 Limitations
 -----------
@@ -79,3 +80,10 @@ It accepts an opaque pointer of a request and its size which can be defined by u
 and provides an opaque pointer for a response and its length.
 PF and VF out of tree driver can define its own request and response based on the message id
 of the mailbox.
+
+Get BAR addresses
+-----------------
+
+Out of tree drivers can retrieve PCI BAR addresses of the device using the API
+``rte_pmd_rvu_lf_bar_get()``. This helps PF/VF drivers to configure the
+registers of the hardware device.
diff --git a/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c b/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c
index 156b9460c1..3a3971ecd3 100644
--- a/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c
+++ b/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c
@@ -103,6 +103,30 @@ rte_pmd_rvu_lf_irq_unregister(uint8_t dev_id, unsigned int irq,
 	return roc_rvu_lf_irq_unregister(roc_rvu_lf, irq, (roc_rvu_lf_intr_cb_fn)cb, data);
 }
 
+int
+rte_pmd_rvu_lf_bar_get(uint8_t dev_id, uint8_t bar_num, size_t *va, size_t *mask)
+{
+	struct roc_rvu_lf *roc_rvu_lf;
+	struct rte_rawdev *rawdev;
+
+	rawdev = rte_rawdev_pmd_get_dev(dev_id);
+	if (rawdev == NULL)
+		return -EINVAL;
+
+	roc_rvu_lf = (struct roc_rvu_lf *)rawdev->dev_private;
+
+	if (bar_num > PCI_MAX_RESOURCE ||
+			(roc_rvu_lf->pci_dev->mem_resource[bar_num].addr == NULL)) {
+		*va = 0;
+		*mask = 0;
+		return -ENOTSUP;
+	}
+	*va = (size_t)(roc_rvu_lf->pci_dev->mem_resource[bar_num].addr);
+	*mask = (size_t)(roc_rvu_lf->pci_dev->mem_resource[bar_num].len - 1);
+
+	return 0;
+}
+
 uint16_t
 rte_pmd_rvu_lf_npa_pf_func_get(void)
 {
diff --git a/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf_driver.h b/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf_driver.h
index 9c4ede2602..e405831ce1 100644
--- a/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf_driver.h
+++ b/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf_driver.h
@@ -193,6 +193,24 @@ __rte_internal
 int rte_pmd_rvu_lf_msg_process(uint8_t dev_id, uint16_t vf, uint16_t msg_id,
 			       void *req, uint16_t req_len, void *rsp, uint16_t rsp_len);
 
+/**
+ * Get BAR addresses for the RVU LF device.
+ *
+ * @param dev_id
+ *   device id of RVU LF device
+ * @param bar_num
+ *   BAR number for which address is required
+ * @param[out] va
+ *    Virtual address of the BAR. 0 if not mapped
+ * @param[out] mask
+ *    BAR address mask, 0 if not mapped
+ *
+ * @return
+ *   Returns 0 on success, negative error code otherwise
+ */
+__rte_internal
+int rte_pmd_rvu_lf_bar_get(uint8_t dev_id, uint8_t bar_num, size_t *va, size_t *mask);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/raw/cnxk_rvu_lf/version.map b/drivers/raw/cnxk_rvu_lf/version.map
index aa974f629e..012f05d1e4 100644
--- a/drivers/raw/cnxk_rvu_lf/version.map
+++ b/drivers/raw/cnxk_rvu_lf/version.map
@@ -1,6 +1,7 @@
 INTERNAL {
 	global:
 
+	rte_pmd_rvu_lf_bar_get;
 	rte_pmd_rvu_lf_irq_register;
 	rte_pmd_rvu_lf_irq_unregister;
 	rte_pmd_rvu_lf_msg_handler_register;
-- 
2.25.1