[11/11] crypto/cnxk: add PMD API to get qp stats

Message ID 20240905074631.1462357-12-ktejasree@marvell.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers
Series fixes and improvements to cnxk crypto PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Tejasree Kondoj Sept. 5, 2024, 7:46 a.m. UTC
From: Anoob Joseph <anoobj@marvell.com>

Add PMD API to get CPT LF(QP) stats.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c  | 32 +++++++++++++++++++++
 drivers/crypto/cnxk/rte_pmd_cnxk_crypto.h | 34 +++++++++++++++++++++++
 drivers/crypto/cnxk/version.map           |  1 +
 3 files changed, 67 insertions(+)
  

Patch

diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index a7d58a5445..2355bc3737 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -1161,3 +1161,35 @@  rte_pmd_cnxk_crypto_cptr_write(struct rte_pmd_cnxk_crypto_qptr *qptr,
 
 	return 0;
 }
+
+int
+rte_pmd_cnxk_crypto_qp_stats_get(struct rte_pmd_cnxk_crypto_qptr *qptr,
+				 struct rte_pmd_cnxk_crypto_qp_stats *stats)
+{
+	struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
+	struct roc_cpt_lf *lf;
+
+	if (unlikely(qptr == NULL)) {
+		plt_err("Invalid queue pair pointer");
+		return -EINVAL;
+	}
+
+	if (unlikely(stats == NULL)) {
+		plt_err("Invalid stats pointer");
+		return -EINVAL;
+	}
+
+	if (unlikely(roc_model_is_cn9k())) {
+		plt_err("Invalid cnxk model");
+		return -EINVAL;
+	}
+
+	lf = &qp->lf;
+
+	stats->ctx_enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
+	stats->ctx_enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
+	stats->ctx_dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
+	stats->ctx_dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
+
+	return 0;
+}
diff --git a/drivers/crypto/cnxk/rte_pmd_cnxk_crypto.h b/drivers/crypto/cnxk/rte_pmd_cnxk_crypto.h
index 454261022b..02278605a2 100644
--- a/drivers/crypto/cnxk/rte_pmd_cnxk_crypto.h
+++ b/drivers/crypto/cnxk/rte_pmd_cnxk_crypto.h
@@ -30,6 +30,23 @@  struct rte_pmd_cnxk_crypto_qptr;
  */
 struct rte_pmd_cnxk_crypto_cptr;
 
+/**
+ *
+ * @brief Crypto CNXK queue pair stats.
+ *
+ * This structure represents the queue pair stats retrieved from CPT HW queue.
+ */
+struct rte_pmd_cnxk_crypto_qp_stats {
+	/** Packet counter of the packets that used CPT context cache and was encrypted */
+	uint64_t ctx_enc_pkts;
+	/** Byte counter of the packets that used CPT context cache and was encrypted */
+	uint64_t ctx_enc_bytes;
+	/** Packet counter of the packets that used CPT context cache and was decrypted */
+	uint64_t ctx_dec_pkts;
+	/** Byte counter of the packets that used CPT context cache and was decrypted */
+	uint64_t ctx_dec_bytes;
+};
+
 /**
  * @brief Crypto CNXK PMD session structure.
  *
@@ -176,4 +193,21 @@  int rte_pmd_cnxk_crypto_cptr_write(struct rte_pmd_cnxk_crypto_qptr *qptr,
 				   struct rte_pmd_cnxk_crypto_cptr *cptr, void *data,
 				   uint32_t len);
 
+/**
+ * Get the HW Queue Pair (LF) stats.
+ *
+ * @param qptr
+ *  Pointer obtained with ``rte_pmd_cnxk_crypto_qptr_get``.
+ * @param[out] stats
+ *  Pointer to the structure where stats will be copied.
+ *
+ * @return
+ *   - 0 On success.
+ *   - Negative value on error.
+ *     - -EINVAL if the input parameters are invalid.
+ */
+__rte_experimental
+int rte_pmd_cnxk_crypto_qp_stats_get(struct rte_pmd_cnxk_crypto_qptr *qptr,
+				     struct rte_pmd_cnxk_crypto_qp_stats *stats);
+
 #endif /* _PMD_CNXK_CRYPTO_H_ */
diff --git a/drivers/crypto/cnxk/version.map b/drivers/crypto/cnxk/version.map
index 6e51f7be1a..05724e69e4 100644
--- a/drivers/crypto/cnxk/version.map
+++ b/drivers/crypto/cnxk/version.map
@@ -10,6 +10,7 @@  EXPERIMENTAL {
 	rte_pmd_cnxk_crypto_cptr_get;
 	rte_pmd_cnxk_crypto_cptr_read;
 	rte_pmd_cnxk_crypto_cptr_write;
+	rte_pmd_cnxk_crypto_qp_stats_get;
 };
 
 INTERNAL {