]> git.droids-corp.org - dpdk.git/commitdiff
cryptodev: add asymmetric session user data API
authorCiara Power <ciara.power@intel.com>
Fri, 11 Feb 2022 09:29:08 +0000 (09:29 +0000)
committerAkhil Goyal <gakhil@marvell.com>
Sat, 12 Feb 2022 09:26:39 +0000 (10:26 +0100)
A user data field is added to the asymmetric session structure.
Relevant API added to get/set the field.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
app/test-crypto-perf/main.c
app/test/test_cryptodev_asym.c
doc/guides/prog_guide/cryptodev_lib.rst
doc/guides/rel_notes/release_22_03.rst
lib/cryptodev/cryptodev_pmd.h
lib/cryptodev/rte_cryptodev.c
lib/cryptodev/rte_cryptodev.h
lib/cryptodev/rte_cryptodev_trace.h
lib/cryptodev/version.map

index 2531de43a2aad0ddacb462a6c787866231bab319..35a11935256efc575bf155efb9beb3130de5871d 100644 (file)
@@ -78,7 +78,7 @@ create_asym_op_pool_socket(int32_t socket_id, uint32_t nb_sessions)
                snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
                         socket_id);
                mpool = rte_cryptodev_asym_session_pool_create(mp_name,
-                               nb_sessions, 0, socket_id);
+                               nb_sessions, 0, 0, socket_id);
                if (mpool == NULL) {
                        printf("Cannot create pool \"%s\" on socket %d\n",
                               mp_name, socket_id);
index d8906c679c862b3909e4fcb3fece08ea768754d2..e3eb0e33d135d29478816a8ed0ed271270067c72 100644 (file)
@@ -893,7 +893,7 @@ testsuite_setup(void)
        }
 
        ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-                       "test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+                       "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
                        SOCKET_ID_ANY);
 
        TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
index 2607a9a7d72f1db855cbdab1cc246bab8f2d149e..ba4c592b84ade5762fde4647de0fb904ab3fd56b 100644 (file)
@@ -1110,6 +1110,25 @@ They operate on data buffer of type ``rte_crypto_param``.
 
 See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct
 
+Private user data
+~~~~~~~~~~~~~~~~~
+
+Similar to symmetric above, asymmetric also has a set and get API that provides a
+mechanism for an application to store and retrieve the private user data information
+stored along with the crypto session.
+
+.. code-block:: c
+
+       int rte_cryptodev_asym_session_set_user_data(void *sess,
+               void *data, uint16_t size);
+
+       void * rte_cryptodev_asym_session_get_user_data(void *sess);
+
+Please note the ``size`` passed to set API cannot be bigger than the predefined
+``user_data_sz`` when creating the session mempool, otherwise the function will
+return an error. Also when ``user_data_sz`` was defined as ``0`` when
+creating the session mempool, the get API will always return ``NULL``.
+
 Asymmetric crypto Sample code
 -----------------------------
 
index 697fe4784194b8ab6a2dfc0af21a686848d133a5..d658da85a9c6ef9572909c365ae2f1eeef25c682 100644 (file)
@@ -121,6 +121,10 @@ New Features
 
   * Added LED OEM support.
 
+* **Added an API for private user data in asymmetric crypto session.**
+
+  An API was added to get/set an asymmetric crypto session's user data.
+
 * **Updated Marvell cnxk crypto PMD.**
 
   * Added SHA256-HMAC support in lookaside protocol (IPsec) for CN10K.
@@ -186,7 +190,7 @@ API Changes
 * cryptodev: The asymmetric session handling was modified to use a single
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
-  session header and max size for a device private session data.
+  session header, max size for a device private session data, and user data size.
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
index 63f9cf5427318a5d958afc52bf33737bc15acb18..d91902f6e0fe4587c7e2aa17b64b73d7fbe13005 100644 (file)
@@ -634,7 +634,9 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {
        /**< Session driver ID. */
        uint16_t max_priv_data_sz;
        /**< Size of private data used when creating mempool */
-       uint8_t padding[5];
+       uint16_t user_data_sz;
+       /**< Session user data will be placed after sess_data */
+       uint8_t padding[3];
        uint8_t sess_private_data[0];
 };
 
index 562cb4a2c489b91db1212611c3c53608ad3ccd2c..91d48d5886e4991b7438d55426811adf9c13647e 100644 (file)
@@ -210,6 +210,8 @@ struct rte_cryptodev_sym_session_pool_private_data {
 struct rte_cryptodev_asym_session_pool_private_data {
        uint16_t max_priv_session_sz;
        /**< Size of private session data used when creating mempool */
+       uint16_t user_data_sz;
+       /**< Session user data will be placed after sess_private_data */
 };
 
 int
@@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-       uint32_t cache_size, int socket_id)
+       uint32_t cache_size, uint16_t user_data_size, int socket_id)
 {
        struct rte_mempool *mp;
        struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
@@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
                return NULL;
        }
 
-       obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+       obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+                       user_data_size;
        obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
 
        mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
@@ -1842,9 +1845,10 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
                return NULL;
        }
        pool_priv->max_priv_session_sz = max_priv_sz;
+       pool_priv->user_data_sz = user_data_size;
 
        rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
-               cache_size, mp);
+               user_data_size, cache_size, mp);
        return mp;
 }
 
@@ -1959,10 +1963,11 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
        }
 
        sess->driver_id = dev->driver_id;
+       sess->user_data_sz = pool_priv->user_data_sz;
        sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
 
        /* Clear device session pointer.*/
-       memset(sess->sess_private_data, 0, session_priv_data_sz);
+       memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
@@ -2159,6 +2164,33 @@ rte_cryptodev_sym_session_get_user_data(
        return (void *)(sess->sess_data + sess->nb_drivers);
 }
 
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+       struct rte_cryptodev_asym_session *sess = session;
+       if (sess == NULL)
+               return -EINVAL;
+
+       if (sess->user_data_sz < size)
+               return -ENOMEM;
+
+       rte_memcpy(sess->sess_private_data +
+                       sess->max_priv_data_sz,
+                       data, size);
+       return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+       struct rte_cryptodev_asym_session *sess = session;
+       if (sess == NULL || sess->user_data_sz == 0)
+               return NULL;
+
+       return (void *)(sess->sess_private_data +
+                       sess->max_priv_data_sz);
+}
+
 static inline void
 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
 {
index 4cf3f6c9d7096bd0c50e007135b55c940ff0022e..1d7bd076800d3edeca18e75c9e5b200c39a1b29d 100644 (file)
@@ -959,6 +959,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
  *   The number of elements in the mempool.
  * @param cache_size
  *   The number of per-lcore cache elements
+ * @param user_data_size
+ *   The size of user data to be placed after session private data.
  * @param socket_id
  *   The *socket_id* argument is the socket identifier in the case of
  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
@@ -971,7 +973,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 __rte_experimental
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-       uint32_t cache_size, int socket_id);
+       uint32_t cache_size, uint16_t user_data_size, int socket_id);
 
 /**
  * Create symmetric crypto session header (generic with no private data)
@@ -1202,6 +1204,37 @@ void *
 rte_cryptodev_sym_session_get_user_data(
                                        struct rte_cryptodev_sym_session *sess);
 
+/**
+ * Store user data in an asymmetric session.
+ *
+ * @param      sess            Session pointer allocated by
+ *                             *rte_cryptodev_asym_session_create*.
+ * @param      data            Pointer to the user data.
+ * @param      size            Size of the user data.
+ *
+ * @return
+ *  - On success, zero.
+ *  - -EINVAL if the session pointer is invalid.
+ *  - -ENOMEM if the available user data size is smaller than the size parameter.
+ */
+__rte_experimental
+int
+rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
+
+/**
+ * Get user data stored in an asymmetric session.
+ *
+ * @param      sess            Session pointer allocated by
+ *                             *rte_cryptodev_asym_session_create*.
+ *
+ * @return
+ *  - On success return pointer to user data.
+ *  - On failure returns NULL.
+ */
+__rte_experimental
+void *
+rte_cryptodev_asym_session_get_user_data(void *sess);
+
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
  * on user provided data.
index 4b48c6619976009a8384b5f00c6885ef2b43dcf7..005a4fe38bef14fcd1ec893c60589a9f64bb9b7c 100644 (file)
@@ -86,9 +86,10 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
        rte_cryptodev_trace_asym_session_pool_create,
        RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
-               uint32_t cache_size, void *mempool),
+               uint16_t user_data_size, uint32_t cache_size, void *mempool),
        rte_trace_point_emit_string(name);
        rte_trace_point_emit_u32(nb_elts);
+       rte_trace_point_emit_u16(user_data_size);
        rte_trace_point_emit_u32(cache_size);
        rte_trace_point_emit_ptr(mempool);
 )
index 44d1aff0e2e0a4be93d753a2a81ef401b1bfeeae..c7c5aefcebe532243d6bdf8973f48009aacd7837 100644 (file)
@@ -101,7 +101,9 @@ EXPERIMENTAL {
        rte_cryptodev_remove_enq_callback;
 
        # added 22.03
+       rte_cryptodev_asym_session_get_user_data;
        rte_cryptodev_asym_session_pool_create;
+       rte_cryptodev_asym_session_set_user_data;
        __rte_cryptodev_trace_asym_session_pool_create;
 };