[v5] cryptodev: add telemetry endpoint for cryptodev capabilities

Message ID b2dae919147f7b7c5a3203f9129b0fd96f722890.1635253852.git.gmuthukrishn@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v5] cryptodev: add telemetry endpoint for cryptodev capabilities |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure
ci/Intel-compilation warning apply issues

Commit Message

Gowrishankar Muthukrishnan Oct. 26, 2021, 1:13 p.m. UTC
  Add telemetry endpoint for cryptodev capabilities.

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
Depends-on: patch-19601 ("cryptodev: add telemetry callbacks")

v5:
 - minor cleanup
---
 lib/cryptodev/rte_cryptodev.c | 61 +++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
  

Comments

Akhil Goyal Oct. 26, 2021, 2:12 p.m. UTC | #1
> Subject: [v5] cryptodev: add telemetry endpoint for cryptodev capabilities
> 
> Add telemetry endpoint for cryptodev capabilities.
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
> Depends-on: patch-19601 ("cryptodev: add telemetry callbacks")
> 
> v5:
>  - minor cleanup
Please send a text to update in the documentation.
Will update it while merging the patch.

Acked-by: Akhil Goyal <gakhil@marvell.com>
  
Gowrishankar Muthukrishnan Oct. 26, 2021, 3:44 p.m. UTC | #2
Hi Akhil,

> Please send a text to update in the documentation.
> Will update it while merging the patch.

diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 25663e552e..223e933bf4 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1308,5 +1308,9 @@ are shown below.
      {"/cryptodev/stats": {"enqueued_count": 0, "dequeued_count": 0,
      "enqueue_err_count": 0, "dequeue_err_count": 0}}

+#. Get the capabilities of a particular Crypto device::
+        --> /cryptodev/caps,0
+        {"/cryptodev/caps": {"crypto_caps": [<array of serialized bytes of
+        capabilities>], "crypto_caps_n": <number of capabilities>}}
 For more information on how to use the Telemetry interface, see
 the :doc:`../howto/telemetry`.

Thanks,
Gowrishankar
> 
> Acked-by: Akhil Goyal <gakhil@marvell.com>
  
Akhil Goyal Oct. 26, 2021, 6:34 p.m. UTC | #3
> > Please send a text to update in the documentation.
> > Will update it while merging the patch.
> 
> diff --git a/doc/guides/prog_guide/cryptodev_lib.rst
> b/doc/guides/prog_guide/cryptodev_lib.rst
> index 25663e552e..223e933bf4 100644
> --- a/doc/guides/prog_guide/cryptodev_lib.rst
> +++ b/doc/guides/prog_guide/cryptodev_lib.rst
> @@ -1308,5 +1308,9 @@ are shown below.
>       {"/cryptodev/stats": {"enqueued_count": 0, "dequeued_count": 0,
>       "enqueue_err_count": 0, "dequeue_err_count": 0}}
> 
> +#. Get the capabilities of a particular Crypto device::
> +        --> /cryptodev/caps,0
> +        {"/cryptodev/caps": {"crypto_caps": [<array of serialized bytes of
> +        capabilities>], "crypto_caps_n": <number of capabilities>}}
>  For more information on how to use the Telemetry interface, see
>  the :doc:`../howto/telemetry`.
> 
Updated and applied to dpdk-next-crypto
Release notes also updated.
Thanks.


> > Acked-by: Akhil Goyal <gakhil@marvell.com>
  

Patch

diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index f9e241c60a..35005f83af 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -2503,6 +2503,64 @@  cryptodev_handle_dev_stats(const char *cmd __rte_unused,
 	return 0;
 }
 
+#define CRYPTO_CAPS_SZ                                             \
+	(RTE_ALIGN_CEIL(sizeof(struct rte_cryptodev_capabilities), \
+					sizeof(uint64_t)) /        \
+	 sizeof(uint64_t))
+
+static int
+crypto_caps_array(struct rte_tel_data *d,
+		  const struct rte_cryptodev_capabilities *capabilities)
+{
+	const struct rte_cryptodev_capabilities *dev_caps;
+	uint64_t caps_val[CRYPTO_CAPS_SZ];
+	unsigned int i = 0, j;
+
+	rte_tel_data_start_array(d, RTE_TEL_U64_VAL);
+
+	while ((dev_caps = &capabilities[i++])->op !=
+	   RTE_CRYPTO_OP_TYPE_UNDEFINED) {
+		memset(&caps_val, 0, CRYPTO_CAPS_SZ * sizeof(caps_val[0]));
+		rte_memcpy(caps_val, dev_caps, sizeof(capabilities[0]));
+		for (j = 0; j < CRYPTO_CAPS_SZ; j++)
+			rte_tel_data_add_array_u64(d, caps_val[j]);
+	}
+
+	return i;
+}
+
+static int
+cryptodev_handle_dev_caps(const char *cmd __rte_unused, const char *params,
+			  struct rte_tel_data *d)
+{
+	struct rte_cryptodev_info dev_info;
+	struct rte_tel_data *crypto_caps;
+	int crypto_caps_n;
+	char *end_param;
+	int dev_id;
+
+	if (!params || strlen(params) == 0 || !isdigit(*params))
+		return -EINVAL;
+
+	dev_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
+	if (!rte_cryptodev_is_valid_dev(dev_id))
+		return -EINVAL;
+
+	rte_tel_data_start_dict(d);
+	crypto_caps = rte_tel_data_alloc();
+	if (!crypto_caps)
+		return -ENOMEM;
+
+	rte_cryptodev_info_get(dev_id, &dev_info);
+	crypto_caps_n = crypto_caps_array(crypto_caps, dev_info.capabilities);
+	rte_tel_data_add_dict_container(d, "crypto_caps", crypto_caps, 0);
+	rte_tel_data_add_dict_int(d, "crypto_caps_n", crypto_caps_n);
+
+	return 0;
+}
+
 RTE_INIT(cryptodev_init_fp_ops)
 {
 	uint32_t i;
@@ -2522,4 +2580,7 @@  RTE_INIT(cryptodev_init_telemetry)
 	rte_telemetry_register_cmd("/cryptodev/stats",
 			cryptodev_handle_dev_stats,
 			"Returns the stats for a cryptodev. Parameters: int dev_id");
+	rte_telemetry_register_cmd("/cryptodev/caps",
+			cryptodev_handle_dev_caps,
+			"Returns the capabilities for a cryptodev. Parameters: int dev_id");
 }