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 <gak...@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

Reply via email to