[3/3] eventdev/crypto: add params set/get APIs

Message ID 20230107161852.3708690-3-s.v.naga.harish.k@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series [1/3] eventdev/eth_rx: add params set/get APIs |

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/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Naga Harish K, S V Jan. 7, 2023, 4:18 p.m. UTC
  The adapter configuration parameters defined in the
``struct rte_event_crypto_adapter_params`` can be configured
and retrieved using ``rte_event_crypto_adapter_set_params``
and ``rte_event_eth_rx_adapter_get_params`` respectively.

Signed-off-by: Naga Harish K S V <s.v.naga.harish.k@intel.com>
---
 app/test/test_event_crypto_adapter.c          | 63 +++++++++++++++++++
 .../prog_guide/event_crypto_adapter.rst       | 19 ++++++
 lib/eventdev/rte_event_crypto_adapter.c       | 46 ++++++++++++++
 lib/eventdev/rte_event_crypto_adapter.h       | 53 ++++++++++++++++
 lib/eventdev/version.map                      |  2 +
 5 files changed, 183 insertions(+)
  

Patch

diff --git a/app/test/test_event_crypto_adapter.c b/app/test/test_event_crypto_adapter.c
index a38e389abd..c443192c58 100644
--- a/app/test/test_event_crypto_adapter.c
+++ b/app/test/test_event_crypto_adapter.c
@@ -272,6 +272,65 @@  test_crypto_adapter_stats(void)
 	return TEST_SUCCESS;
 }
 
+static int
+test_crypto_adapter_params(void)
+{
+	int err;
+	struct rte_event_crypto_adapter_params in_params;
+	struct rte_event_crypto_adapter_params out_params;
+
+	/* Case 1: Get the default value of mbufs processed by adapter */
+	err = rte_event_crypto_adapter_get_params(TEST_ADAPTER_ID, &out_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	/* Case 2: Set max_nb = 32 (=BATCH_SEIZE) */
+	in_params.max_nb = 32;
+
+	err = rte_event_crypto_adapter_set_params(TEST_ADAPTER_ID, &in_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	err = rte_event_crypto_adapter_get_params(TEST_ADAPTER_ID, &out_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+	TEST_ASSERT(in_params.max_nb == out_params.max_nb, "Expected %u got %u",
+		    in_params.max_nb, out_params.max_nb);
+
+	/* Case 3: Set max_nb = 192 */
+	in_params.max_nb = 192;
+
+	err = rte_event_crypto_adapter_set_params(TEST_ADAPTER_ID, &in_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	err = rte_event_crypto_adapter_get_params(TEST_ADAPTER_ID, &out_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+	TEST_ASSERT(in_params.max_nb == out_params.max_nb, "Expected %u got %u",
+		    in_params.max_nb, out_params.max_nb);
+
+	/* Case 4: Set max_nb = 256 */
+	in_params.max_nb = 256;
+
+	err = rte_event_crypto_adapter_set_params(TEST_ADAPTER_ID, &in_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	err = rte_event_crypto_adapter_get_params(TEST_ADAPTER_ID, &out_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+	TEST_ASSERT(in_params.max_nb == out_params.max_nb, "Expected %u got %u",
+		    in_params.max_nb, out_params.max_nb);
+
+	/* Case 5: Set max_nb = 30(<BATCH_SIZE) */
+	in_params.max_nb = 30;
+
+	err = rte_event_crypto_adapter_set_params(TEST_ADAPTER_ID, &in_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	/* Case 6: Set max_nb = 512 */
+	in_params.max_nb = 512;
+
+	err = rte_event_crypto_adapter_set_params(TEST_ADAPTER_ID, &in_params);
+	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
+
+	return TEST_SUCCESS;
+}
+
 static int
 test_op_forward_mode(uint8_t session_less)
 {
@@ -1454,6 +1513,10 @@  static struct unit_test_suite functional_testsuite = {
 				test_crypto_adapter_free,
 				test_crypto_adapter_stats),
 
+		TEST_CASE_ST(test_crypto_adapter_create,
+				test_crypto_adapter_free,
+				test_crypto_adapter_params),
+
 		TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
 				test_crypto_adapter_stop,
 				test_session_with_op_forward_mode),
diff --git a/doc/guides/prog_guide/event_crypto_adapter.rst b/doc/guides/prog_guide/event_crypto_adapter.rst
index 554df7e358..ff23c952dc 100644
--- a/doc/guides/prog_guide/event_crypto_adapter.rst
+++ b/doc/guides/prog_guide/event_crypto_adapter.rst
@@ -333,3 +333,22 @@  in struct ``rte_event_crypto_adapter_stats``. The received packet and
 enqueued event counts are a sum of the counts from the eventdev PMD callbacks
 if the callback is supported, and the counts maintained by the service function,
 if one exists.
+
+Set/Get adapter configuration parameters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The configuration parameters of adapter can be set/read using
+``rte_event_crypto_adapter_set_params()`` and
+``rte_event_crypto_adapter_get_params()`` respectively. The parameters that
+can be set/read are defined in ``struct rte_event_crypto_adapter_params``.
+
+``rte_event_crypto_adapter_create()`` configures the adapter with
+default value for maximum packets processed per request to 128.
+``rte_event_crypto_adapter_set_params()`` function allows to reconfigure
+maximum number of packets processed by adapter per service request. This is
+alternative to configuring the maximum packets processed per request by adapter
+by using ``rte_event_crypto_adapter_create_ext()`` with parameter
+``rte_event_crypto_adapter_conf::max_nb``.
+
+``rte_event_crypto_adapter_get_parmas()`` function retrieves the configuration
+parameters that are defined in ``struct rte_event_crypto_adapter_params``.
diff --git a/lib/eventdev/rte_event_crypto_adapter.c b/lib/eventdev/rte_event_crypto_adapter.c
index 3c585d7b0d..6366e4a25f 100644
--- a/lib/eventdev/rte_event_crypto_adapter.c
+++ b/lib/eventdev/rte_event_crypto_adapter.c
@@ -1323,6 +1323,52 @@  rte_event_crypto_adapter_stats_reset(uint8_t id)
 	return 0;
 }
 
+int
+rte_event_crypto_adapter_set_params(uint8_t id,
+		struct rte_event_crypto_adapter_params *params)
+{
+	struct event_crypto_adapter *adapter;
+
+	EVENT_CRYPTO_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL);
+
+	if (params == NULL) {
+		RTE_EDEV_LOG_ERR("params pointer is NULL\n");
+		return -EINVAL;
+	}
+
+	adapter = eca_id_to_adapter(id);
+	if (adapter == NULL)
+		return -EINVAL;
+
+	rte_spinlock_lock(&adapter->lock);
+	adapter->max_nb = params->max_nb;
+	rte_spinlock_unlock(&adapter->lock);
+
+	return 0;
+}
+
+int
+rte_event_crypto_adapter_get_params(uint8_t id,
+		struct rte_event_crypto_adapter_params *params)
+{
+	struct event_crypto_adapter *adapter;
+
+	EVENT_CRYPTO_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL);
+
+	if (params == NULL) {
+		RTE_EDEV_LOG_ERR("params pointer is NULL\n");
+		return -EINVAL;
+	}
+
+	adapter = eca_id_to_adapter(id);
+	if (adapter == NULL)
+		return -EINVAL;
+
+	params->max_nb = adapter->max_nb;
+
+	return 0;
+}
+
 int
 rte_event_crypto_adapter_service_id_get(uint8_t id, uint32_t *service_id)
 {
diff --git a/lib/eventdev/rte_event_crypto_adapter.h b/lib/eventdev/rte_event_crypto_adapter.h
index 83d154a6ce..ed744526e9 100644
--- a/lib/eventdev/rte_event_crypto_adapter.h
+++ b/lib/eventdev/rte_event_crypto_adapter.h
@@ -138,6 +138,8 @@ 
  *  - rte_event_crypto_adapter_stop()
  *  - rte_event_crypto_adapter_stats_get()
  *  - rte_event_crypto_adapter_stats_reset()
+ *  - rte_event_crypto_adapter_get_params()
+ *  - rte_event_crypto_adapter_set_params()
 
  * The application creates an instance using rte_event_crypto_adapter_create()
  * or rte_event_crypto_adapter_create_ext().
@@ -253,6 +255,17 @@  struct rte_event_crypto_adapter_conf {
 	 */
 };
 
+/**
+ * Adapter configuration parameters
+ */
+struct rte_event_crypto_adapter_params {
+	uint32_t max_nb;
+	/**< The adapter can return early if it has processed at least
+	 * max_nb crypto ops. This isn't treated as a requirement; batching
+	 * may cause the adapter to process more than max_nb crypto ops.
+	 */
+};
+
 #define RTE_EVENT_CRYPTO_ADAPTER_EVENT_VECTOR	0x1
 /**< This flag indicates that crypto operations processed on the crypto
  * adapter need to be vectorized
@@ -594,6 +607,46 @@  rte_event_crypto_adapter_service_id_get(uint8_t id, uint32_t *service_id);
 int
 rte_event_crypto_adapter_event_port_get(uint8_t id, uint8_t *event_port_id);
 
+/**
+ * Set the adapter configuration parameters
+ *
+ * This api need to be called after adding at least one qp to adapter
+ *
+ * @param id
+ *  Adapter identifier
+ *
+ * @param params
+ *  A pointer to structure of type struct rte_event_crypto_adapter_params
+ *  with configuration parameter values.
+ *
+ * @return
+ *  -  0: Success
+ *  - <0: Error code on failure
+ */
+__rte_experimental
+int
+rte_event_crypto_adapter_set_params(uint8_t id,
+		struct rte_event_crypto_adapter_params *params);
+
+/**
+ * Get the adapter configuration parameters
+ *
+ * @param id
+ *  Adapter identifier
+ *
+ * @param[out] params
+ *  A pointer to structure of type struct rte_event_crypto_adapter_params
+ *  containing valid adapter parameters when return value is 0
+ *
+ * @return
+ *  -  0: Success
+ *  - <0: Error code on failure
+ */
+__rte_experimental
+int
+rte_event_crypto_adapter_get_params(uint8_t id,
+		struct rte_event_crypto_adapter_params *params);
+
 /**
  * Retrieve vector limits for a given event dev and crypto dev pair.
  * @see rte_event_crypto_adapter_vector_limits
diff --git a/lib/eventdev/version.map b/lib/eventdev/version.map
index 55e8cb514c..d17e67356c 100644
--- a/lib/eventdev/version.map
+++ b/lib/eventdev/version.map
@@ -120,6 +120,8 @@  EXPERIMENTAL {
 	rte_event_eth_tx_adapter_queue_stop;
 
 	# added in 23.03
+	rte_event_crypto_adapter_get_params;
+	rte_event_crypto_adapter_set_params;
 	rte_event_eth_rx_adapter_get_params;
 	rte_event_eth_rx_adapter_set_params;
 	rte_event_eth_tx_adapter_get_params;