[v2,1/3] common/cnxk: update timer base code

Message ID 20231211132320.1254-1-pbhagavatula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series [v2,1/3] common/cnxk: update timer base code |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Pavan Nikhilesh Bhagavatula Dec. 11, 2023, 1:23 p.m. UTC
  From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Update event timer base code.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
v2 Changes:
- Split patches.

 drivers/common/cnxk/hw/tim.h   |  5 +++--
 drivers/common/cnxk/roc_mbox.h | 11 +++++++++++
 drivers/common/cnxk/roc_sso.c  |  2 +-
 drivers/common/cnxk/roc_tim.c  | 27 ++++++++++++++++++++++++++-
 drivers/common/cnxk/roc_tim.h  |  3 +++
 5 files changed, 44 insertions(+), 4 deletions(-)

--
2.25.1
  

Patch

diff --git a/drivers/common/cnxk/hw/tim.h b/drivers/common/cnxk/hw/tim.h
index 61c38ae175..82b094e3dc 100644
--- a/drivers/common/cnxk/hw/tim.h
+++ b/drivers/common/cnxk/hw/tim.h
@@ -49,7 +49,8 @@ 
 #define TIM_LF_RING_REL		   (0x400)

 #define TIM_MAX_INTERVAL_TICKS ((1ULL << 32) - 1)
-#define TIM_MAX_BUCKET_SIZE    ((1ULL << 20) - 1)
-#define TIM_MIN_BUCKET_SIZE    3
+#define TIM_MAX_BUCKET_SIZE    ((1ULL << 20) - 2)
+#define TIM_MIN_BUCKET_SIZE    1
+#define TIM_BUCKET_WRAP_SIZE   3

 #endif /* __TIM_HW_H__ */
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index 05434aec5a..4590e5f2dd 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -154,6 +154,8 @@  struct mbox_msghdr {
 	M(TIM_DISABLE_RING, 0x804, tim_disable_ring, tim_ring_req, msg_rsp)    \
 	M(TIM_GET_MIN_INTVL, 0x805, tim_get_min_intvl, tim_intvl_req,          \
 	  tim_intvl_rsp)                                                       \
+	M(TIM_CAPTURE_COUNTERS, 0x806, tim_capture_counters, msg_req,          \
+	  tim_capture_rsp)                                                     \
 	/* CPT mbox IDs (range 0xA00 - 0xBFF) */                               \
 	M(CPT_LF_ALLOC, 0xA00, cpt_lf_alloc, cpt_lf_alloc_req_msg, msg_rsp)    \
 	M(CPT_LF_FREE, 0xA01, cpt_lf_free, msg_req, msg_rsp)                   \
@@ -2541,6 +2543,10 @@  enum tim_clk_srcs {
 	TIM_CLK_SRCS_GPIO = 1,
 	TIM_CLK_SRCS_GTI = 2,
 	TIM_CLK_SRCS_PTP = 3,
+	TIM_CLK_SRCS_SYNCE = 4,
+	TIM_CLK_SRCS_BTS = 5,
+	TIM_CLK_SRCS_EXT_MIO = 6,
+	TIM_CLK_SRCS_EXT_GTI = 7,
 	TIM_CLK_SRSC_INVALID,
 };

@@ -2652,6 +2658,11 @@  struct tim_intvl_rsp {
 	uint64_t __io intvl_ns;
 };

+struct tim_capture_rsp {
+	struct mbox_msghdr hdr;
+	uint64_t __io counters[TIM_CLK_SRSC_INVALID];
+};
+
 struct sdp_node_info {
 	/* Node to which this PF belons to */
 	uint8_t __io node_id;
diff --git a/drivers/common/cnxk/roc_sso.c b/drivers/common/cnxk/roc_sso.c
index 748d287bad..f09b535c80 100644
--- a/drivers/common/cnxk/roc_sso.c
+++ b/drivers/common/cnxk/roc_sso.c
@@ -891,7 +891,7 @@  roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, ui
 			goto sso_msix_fail;
 		}

-		nb_tim_lfs = nb_tim_lfs ? PLT_MIN(nb_tim_lfs, free_tim_lfs) : free_tim_lfs;
+		nb_tim_lfs = PLT_MIN(nb_tim_lfs, free_tim_lfs);
 	}

 	/* 2 error interrupt per TIM LF */
diff --git a/drivers/common/cnxk/roc_tim.c b/drivers/common/cnxk/roc_tim.c
index f8607b2852..095afbb9e6 100644
--- a/drivers/common/cnxk/roc_tim.c
+++ b/drivers/common/cnxk/roc_tim.c
@@ -91,6 +91,31 @@  tim_err_desc(int rc)
 	}
 }

+int
+roc_tim_capture_counters(struct roc_tim *roc_tim, uint64_t *counters, uint8_t nb_cntrs)
+{
+	struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+	struct dev *dev = &sso->dev;
+	struct mbox *mbox = mbox_get(dev->mbox);
+	struct tim_capture_rsp *rsp;
+	int rc, i;
+
+	mbox_alloc_msg_tim_capture_counters(mbox);
+	rc = mbox_process_msg(dev->mbox, (void **)&rsp);
+	if (rc) {
+		tim_err_desc(rc);
+		rc = -EIO;
+		goto fail;
+	}
+
+	for (i = 0; i < nb_cntrs; i++)
+		counters[i] = rsp->counters[i];
+
+fail:
+	mbox_put(mbox);
+	return rc;
+}
+
 int
 roc_tim_lf_enable(struct roc_tim *roc_tim, uint8_t ring_id, uint64_t *start_tsc,
 		  uint32_t *cur_bkt)
@@ -138,7 +163,7 @@  roc_tim_lf_disable(struct roc_tim *roc_tim, uint8_t ring_id)
 		goto fail;
 	req->ring = ring_id;

-	rc = mbox_process(dev->mbox);
+	rc = mbox_process(mbox);
 	if (rc) {
 		tim_err_desc(rc);
 		rc = -EIO;
diff --git a/drivers/common/cnxk/roc_tim.h b/drivers/common/cnxk/roc_tim.h
index 7dc9ae0a61..f9a9ad1887 100644
--- a/drivers/common/cnxk/roc_tim.h
+++ b/drivers/common/cnxk/roc_tim.h
@@ -14,6 +14,8 @@  enum roc_tim_clk_src {
 	ROC_TIM_CLK_SRC_PTP,
 	ROC_TIM_CLK_SRC_SYNCE,
 	ROC_TIM_CLK_SRC_BTS,
+	ROC_TIM_CLK_SRC_EXT_MIO,
+	ROC_TIM_CLK_SRC_EXT_GTI,
 	ROC_TIM_CLK_SRC_INVALID,
 };

@@ -48,5 +50,6 @@  int __roc_api roc_tim_lf_alloc(struct roc_tim *roc_tim, uint8_t ring_id,
 int __roc_api roc_tim_lf_free(struct roc_tim *roc_tim, uint8_t ring_id);
 uintptr_t __roc_api roc_tim_lf_base_get(struct roc_tim *roc_tim,
 					uint8_t ring_id);
+int roc_tim_capture_counters(struct roc_tim *roc_tim, uint64_t *counters, uint8_t nb_cntrs);

 #endif