diff mbox series

[16/52] common/cnxk: add npa lf init/fini callback support

Message ID 20210305133918.8005-17-ndabilpuram@marvell.com (mailing list archive)
State Superseded
Delegated to: Jerin Jacob
Headers show
Series Add Marvell CNXK common driver | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nithin Dabilpuram March 5, 2021, 1:38 p.m. UTC
From: Ashwin Sekhar T K <asekhar@marvell.com>

Add support for npa lf init/fini callbacks.

Signed-off-by: Ashwin Sekhar T K <asekhar@marvell.com>
---
 drivers/common/cnxk/roc_npa.c   | 27 +++++++++++++++++++++++++++
 drivers/common/cnxk/roc_npa.h   |  8 ++++++++
 drivers/common/cnxk/version.map |  2 ++
 3 files changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/drivers/common/cnxk/roc_npa.c b/drivers/common/cnxk/roc_npa.c
index c4bcad7..4c45eef 100644
--- a/drivers/common/cnxk/roc_npa.c
+++ b/drivers/common/cnxk/roc_npa.c
@@ -5,6 +5,21 @@ 
 #include "roc_api.h"
 #include "roc_priv.h"
 
+static roc_npa_lf_init_cb_t npa_lf_init_cb;
+static roc_npa_lf_fini_cb_t npa_lf_fini_cb;
+
+void
+roc_npa_lf_init_cb_register(roc_npa_lf_init_cb_t cb)
+{
+	npa_lf_init_cb = cb;
+}
+
+void
+roc_npa_lf_fini_cb_register(roc_npa_lf_fini_cb_t cb)
+{
+	npa_lf_fini_cb = cb;
+}
+
 void
 roc_npa_aura_op_range_set(uint64_t aura_handle, uint64_t start_iova,
 			  uint64_t end_iova)
@@ -717,11 +732,20 @@  npa_lf_init(struct dev *dev, struct plt_pci_device *pci_dev)
 	if (rc)
 		goto npa_fini;
 
+	if (npa_lf_init_cb) {
+		rc = npa_lf_init_cb();
+		if (rc)
+			goto npa_irq_unregister;
+	}
+
 	plt_npa_dbg("npa=%p max_pools=%d pf_func=0x%x msix=0x%x", lf,
 		    roc_idev_npa_maxpools_get(), lf->pf_func, npa_msixoff);
 
 	return 0;
 
+npa_irq_unregister:
+	npa_unregister_irqs(idev->npa);
+
 npa_fini:
 	npa_dev_fini(idev->npa);
 npa_detach:
@@ -750,6 +774,9 @@  npa_lf_fini(void)
 	rc |= npa_detach(idev->npa->mbox);
 	idev_set_defaults(idev);
 
+	if (npa_lf_fini_cb)
+		npa_lf_fini_cb();
+
 	return rc;
 }
 
diff --git a/drivers/common/cnxk/roc_npa.h b/drivers/common/cnxk/roc_npa.h
index ab0b135..4288708 100644
--- a/drivers/common/cnxk/roc_npa.h
+++ b/drivers/common/cnxk/roc_npa.h
@@ -16,6 +16,10 @@ 
  */
 #define ROC_CN9K_NPA_BULK_ALLOC_MAX_PTRS 30
 
+/* Callbacks that are called after NPA lf init/fini respectively */
+typedef int (*roc_npa_lf_init_cb_t)(void);
+typedef void (*roc_npa_lf_fini_cb_t)(void);
+
 /*
  * Generate 64bit handle to have optimized alloc and free aura operation.
  * 0 - ROC_AURA_ID_MASK for storing the aura_id.
@@ -650,4 +654,8 @@  int __roc_api roc_npa_dump(void);
 /* Reset operation performance counter. */
 int __roc_api roc_npa_pool_op_pc_reset(uint64_t aura_handle);
 
+/* Callback registration */
+void __roc_api roc_npa_lf_init_cb_register(roc_npa_lf_init_cb_t cb);
+void __roc_api roc_npa_lf_fini_cb_register(roc_npa_lf_fini_cb_t cb);
+
 #endif /* _ROC_NPA_H_ */
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 02dc3df..c5724d6 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -18,6 +18,8 @@  INTERNAL {
 	roc_npa_dev_fini;
 	roc_npa_dev_init;
 	roc_npa_dump;
+	roc_npa_lf_fini_cb_register;
+	roc_npa_lf_init_cb_register;
 	roc_npa_pool_create;
 	roc_npa_pool_destroy;
 	roc_npa_pool_op_pc_reset;