diff mbox series

[v2,30/32] raw/cnxk_bphy: support for retrieving bphy device memory

Message ID 20210615110345.11057-31-tduszynski@marvell.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series add support for baseband phy | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tomasz Duszynski June 15, 2021, 11:03 a.m. UTC
Allow user to retrieve baseband phy memory resources.

Signed-off-by: Jakub Palider <jpalider@marvell.com>
Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 doc/guides/rawdevs/cnxk_bphy.rst      | 10 +++++++++
 drivers/raw/cnxk_bphy/cnxk_bphy.c     |  3 +++
 drivers/raw/cnxk_bphy/cnxk_bphy_irq.c |  8 +++++++
 drivers/raw/cnxk_bphy/cnxk_bphy_irq.h |  1 +
 drivers/raw/cnxk_bphy/rte_pmd_bphy.h  | 30 +++++++++++++++++++++++++++
 5 files changed, 52 insertions(+)
diff mbox series

Patch

diff --git a/doc/guides/rawdevs/cnxk_bphy.rst b/doc/guides/rawdevs/cnxk_bphy.rst
index 00edca4be..e031f4148 100644
--- a/doc/guides/rawdevs/cnxk_bphy.rst
+++ b/doc/guides/rawdevs/cnxk_bphy.rst
@@ -17,6 +17,7 @@  Features
 The BPHY CGX/RPM implements following features in the rawdev API:
 
 - Access to BPHY CGX/RPM via a set of predefined messages
+- Access to BPHY memory
 
 Device Setup
 ------------
@@ -115,6 +116,15 @@  The former will setup low level interrupt handling while the latter will tear ev
 are also two convenience functions namely ``rte_pmd_bphy_intr_init()`` and
 ``rte_pmd_bphy_intr_fini()`` that take care of all details.
 
+
+Get device memory
+~~~~~~~~~~~~~~~~~
+
+Message is used to read device MMIO address.
+
+Message must have type set to ``CNXK_BPHY_IRQ_MSG_TYPE_MEM_GET``. There's a convenience function
+``rte_pmd_bphy_intr_mem_get()`` available that takes care of retrieving that address.
+
 Self test
 ---------
 
diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy.c b/drivers/raw/cnxk_bphy/cnxk_bphy.c
index 3f8679534..278e26af0 100644
--- a/drivers/raw/cnxk_bphy/cnxk_bphy.c
+++ b/drivers/raw/cnxk_bphy/cnxk_bphy.c
@@ -53,6 +53,9 @@  cnxk_bphy_irq_enqueue_bufs(struct rte_rawdev *dev,
 	case CNXK_BPHY_IRQ_MSG_TYPE_FINI:
 		cnxk_bphy_intr_fini(dev->dev_id);
 		break;
+	case CNXK_BPHY_IRQ_MSG_TYPE_MEM_GET:
+		bphy_dev->queues[queue].rsp = &bphy_dev->mem;
+		break;
 	default:
 		ret = -EINVAL;
 	}
diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy_irq.c b/drivers/raw/cnxk_bphy/cnxk_bphy_irq.c
index 991c2d7ab..13a0d8ad1 100644
--- a/drivers/raw/cnxk_bphy/cnxk_bphy_irq.c
+++ b/drivers/raw/cnxk_bphy/cnxk_bphy_irq.c
@@ -57,3 +57,11 @@  cnxk_bphy_intr_fini(uint16_t dev_id)
 	roc_bphy_intr_fini(irq_chip);
 	bphy_dev->irq_chip = NULL;
 }
+
+struct bphy_mem *
+cnxk_bphy_mem_get(uint16_t dev_id)
+{
+	struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
+
+	return &bphy_dev->mem;
+}
diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy_irq.h b/drivers/raw/cnxk_bphy/cnxk_bphy_irq.h
index 6b59218af..5f87143a0 100644
--- a/drivers/raw/cnxk_bphy/cnxk_bphy_irq.h
+++ b/drivers/raw/cnxk_bphy/cnxk_bphy_irq.h
@@ -31,6 +31,7 @@  struct bphy_device {
 
 int cnxk_bphy_intr_init(uint16_t dev_id);
 void cnxk_bphy_intr_fini(uint16_t dev_id);
+struct bphy_mem *cnxk_bphy_mem_get(uint16_t dev_id);
 uint64_t cnxk_bphy_irq_max_get(uint16_t dev_id);
 
 #endif /* _CNXK_BPHY_IRQ_ */
diff --git a/drivers/raw/cnxk_bphy/rte_pmd_bphy.h b/drivers/raw/cnxk_bphy/rte_pmd_bphy.h
index c667d984e..d08b14b57 100644
--- a/drivers/raw/cnxk_bphy/rte_pmd_bphy.h
+++ b/drivers/raw/cnxk_bphy/rte_pmd_bphy.h
@@ -103,6 +103,7 @@  struct cnxk_bphy_cgx_msg {
 	void *data;
 };
 
+#define cnxk_bphy_mem	    bphy_mem
 #define CNXK_BPHY_DEF_QUEUE 0
 
 enum cnxk_bphy_irq_msg_type {
@@ -115,6 +116,11 @@  enum cnxk_bphy_irq_msg_type {
 
 struct cnxk_bphy_irq_msg {
 	enum cnxk_bphy_irq_msg_type type;
+	/*
+	 * The data field, depending on message type, may point to
+	 * - (deq) struct cnxk_bphy_mem for memory range request response
+	 * - (xxx) NULL
+	 */
 	void *data;
 };
 
@@ -155,4 +161,28 @@  rte_pmd_bphy_intr_fini(uint16_t dev_id)
 	rte_rawdev_enqueue_buffers(dev_id, bufs, 1, CNXK_BPHY_DEF_QUEUE);
 }
 
+static __rte_always_inline struct cnxk_bphy_mem *
+rte_pmd_bphy_intr_mem_get(uint16_t dev_id)
+{
+	struct cnxk_bphy_irq_msg msg = {
+		.type = CNXK_BPHY_IRQ_MSG_TYPE_MEM_GET,
+	};
+	struct rte_rawdev_buf *bufs[1];
+	struct rte_rawdev_buf buf;
+	int ret;
+
+	buf.buf_addr = &msg;
+	bufs[0] = &buf;
+
+	ret = rte_rawdev_enqueue_buffers(dev_id, bufs, 1, CNXK_BPHY_DEF_QUEUE);
+	if (ret)
+		return NULL;
+
+	ret = rte_rawdev_dequeue_buffers(dev_id, bufs, 1, CNXK_BPHY_DEF_QUEUE);
+	if (ret)
+		return NULL;
+
+	return buf.buf_addr;
+}
+
 #endif /* _CNXK_BPHY_H_ */