[4/9] raw/cnxk_rvu_lf: add PMD API to get BAR addresses

Message ID 20240907193311.1342310-5-gakhil@marvell.com (mailing list archive)
State Changes Requested
Delegated to: Jerin Jacob
Headers
Series drivers/raw: introduce cnxk rvu lf device driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Akhil Goyal Sept. 7, 2024, 7:33 p.m. UTC
Added rte_pmd_rvu_lf_bar_get() API to get BAR address
for application to configure hardware.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
---
 doc/guides/rawdevs/cnxk_rvu_lf.rst       |  7 +++++++
 drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c    | 23 +++++++++++++++++++++++
 drivers/raw/cnxk_rvu_lf/rte_pmd_rvu_lf.h | 18 ++++++++++++++++++
 3 files changed, 48 insertions(+)
  

Patch

diff --git a/doc/guides/rawdevs/cnxk_rvu_lf.rst b/doc/guides/rawdevs/cnxk_rvu_lf.rst
index 13184ad4dc..6dfbd466ad 100644
--- a/doc/guides/rawdevs/cnxk_rvu_lf.rst
+++ b/doc/guides/rawdevs/cnxk_rvu_lf.rst
@@ -45,3 +45,10 @@  Get NPA and SSO PF FUNC
 APIs ``rte_pmd_rvu_lf_npa_pf_func_get()`` and ``rte_pmd_rvu_lf_sso_pf_func_get()``
 can be used to get the cnxk NPA PF func and SSO PF func which application
 can use for NPA/SSO specific configuration.
+
+Get BAR addresses
+-----------------
+
+Application can retrieve PCI BAR addresses of the device using the API
+``rte_pmd_rvu_lf_bar_get()``. This helps application 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 2fbde52966..fc9facd852 100644
--- a/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c
+++ b/drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c
@@ -15,6 +15,29 @@ 
 
 #include "rte_pmd_rvu_lf.h"
 
+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/rte_pmd_rvu_lf.h b/drivers/raw/cnxk_rvu_lf/rte_pmd_rvu_lf.h
index c11df14553..50b43b1785 100644
--- a/drivers/raw/cnxk_rvu_lf/rte_pmd_rvu_lf.h
+++ b/drivers/raw/cnxk_rvu_lf/rte_pmd_rvu_lf.h
@@ -50,6 +50,24 @@  uint16_t rte_pmd_rvu_lf_npa_pf_func_get(void);
 __rte_experimental
 uint16_t rte_pmd_rvu_lf_sso_pf_func_get(void);
 
+/**
+ * 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_experimental
+int rte_pmd_rvu_lf_bar_get(uint8_t dev_id, uint8_t bar_num, size_t *va, size_t *mask);
+
 #ifdef __cplusplus
 }
 #endif