app/eventdev: switch sequence number to dynamic mbuf field
[dpdk.git] / lib / librte_cryptodev / rte_cryptodev_pmd.h
index 641dd13..9a8a7e6 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2015-2016 Intel Corporation.
+ * Copyright(c) 2015-2020 Intel Corporation.
  */
 
 #ifndef _RTE_CRYPTODEV_PMD_H_
@@ -41,7 +41,8 @@ extern "C" {
 static const char * const cryptodev_pmd_valid_params[] = {
        RTE_CRYPTODEV_PMD_NAME_ARG,
        RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
-       RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
+       RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
+       NULL
 };
 
 /**
@@ -61,7 +62,6 @@ struct rte_cryptodev_global {
        struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
        /**< Device private data */
        uint8_t nb_devs;                /**< Number of devices found */
-       uint8_t max_devs;               /**< Max number of devices */
 };
 
 /* Cryptodev driver, containing the driver ID */
@@ -71,9 +71,6 @@ struct cryptodev_driver {
        uint8_t id;
 };
 
-/** pointer to global crypto devices data structure. */
-extern struct rte_cryptodev_global *rte_cryptodev_globals;
-
 /**
  * Get the rte_cryptodev structure device pointer for the device. Assumes a
  * valid device index.
@@ -191,13 +188,12 @@ typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
  * @param      qp_id           Queue Pair Index
  * @param      qp_conf         Queue configuration structure
  * @param      socket_id       Socket Index
- * @param      session_pool    Pointer to device session mempool
  *
  * @return     Returns 0 on success.
  */
 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
                uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
-               int socket_id, struct rte_mempool *session_pool);
+               int socket_id);
 
 /**
  * Release memory resources allocated by given queue pair.
@@ -212,15 +208,6 @@ typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
                uint16_t qp_id);
 
-/**
- * Get number of available queue pairs of a device.
- *
- * @param      dev     Crypto device pointer
- *
- * @return     Returns number of queue pairs on success.
- */
-typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
-
 /**
  * Create a session mempool to allocate sessions from
  *
@@ -249,6 +236,17 @@ typedef int (*cryptodev_sym_create_session_pool_t)(
  */
 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
                struct rte_cryptodev *dev);
+/**
+ * Get the size of a asymmetric cryptodev session
+ *
+ * @param      dev             Crypto device pointer
+ *
+ * @return
+ *  - On success returns the size of the session structure for device
+ *  - On failure returns 0
+ */
+typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
+               struct rte_cryptodev *dev);
 
 /**
  * Configure a Crypto session on a device.
@@ -268,7 +266,24 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
                struct rte_crypto_sym_xform *xform,
                struct rte_cryptodev_sym_session *session,
                struct rte_mempool *mp);
-
+/**
+ * Configure a Crypto asymmetric session on a device.
+ *
+ * @param      dev             Crypto device pointer
+ * @param      xform           Single or chain of crypto xforms
+ * @param      priv_sess       Pointer to cryptodev's private session structure
+ * @param      mp              Mempool where the private session is allocated
+ *
+ * @return
+ *  - Returns 0 if private session structure have been created successfully.
+ *  - Returns -EINVAL if input parameters are invalid.
+ *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
+ *  - Returns -ENOMEM if the private session could not be allocated.
+ */
+typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
+               struct rte_crypto_asym_xform *xform,
+               struct rte_cryptodev_asym_session *session,
+               struct rte_mempool *mp);
 /**
  * Free driver private session data.
  *
@@ -277,32 +292,67 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  */
 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
                struct rte_cryptodev_sym_session *sess);
-
 /**
- * Optional API for drivers to attach sessions with queue pair.
+ * Free asymmetric session private data.
+ *
  * @param      dev             Crypto device pointer
- * @param      qp_id           queue pair id for attaching session
- * @param      priv_sess       Pointer to cryptodev's private session structure
+ * @param      sess            Cryptodev session structure
+ */
+typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
+               struct rte_cryptodev_asym_session *sess);
+/**
+ * Perform actual crypto processing (encrypt/digest or auth/decrypt)
+ * on user provided data.
+ *
+ * @param      dev     Crypto device pointer
+ * @param      sess    Cryptodev session structure
+ * @param      ofs     Start and stop offsets for auth and cipher operations
+ * @param      vec     Vectorized operation descriptor
+ *
  * @return
- *  - Return 0 on success
+ *  - Returns number of successfully processed packets.
+ *
  */
-typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
-                 struct rte_cryptodev *dev,
-                 uint16_t qp_id,
-                 void *session_private);
+typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
+       (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
+       union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
 
 /**
- * Optional API for drivers to detach sessions from queue pair.
- * @param      dev             Crypto device pointer
- * @param      qp_id           queue pair id for detaching session
- * @param      priv_sess       Pointer to cryptodev's private session structure
+ * Typedef that the driver provided to get service context private date size.
+ *
+ * @param      dev     Crypto device pointer.
+ *
  * @return
- *  - Return 0 on success
+ *   - On success return the size of the device's service context private data.
+ *   - On failure return negative integer.
  */
-typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
-                 struct rte_cryptodev *dev,
-                 uint16_t qp_id,
-                 void *session_private);
+typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
+
+/**
+ * Typedef that the driver provided to configure raw data-path context.
+ *
+ * @param      dev             Crypto device pointer.
+ * @param      qp_id           Crypto device queue pair index.
+ * @param      service_type    Type of the service requested.
+ * @param      ctx             The raw data-path context data.
+ * @param      sess_type       session type.
+ * @param      session_ctx     Session context data. If NULL the driver
+ *                             shall only configure the drv_ctx_data in
+ *                             ctx buffer. Otherwise the driver shall only
+ *                             parse the session_ctx to set appropriate
+ *                             function pointers in ctx.
+ * @param      is_update       Set 0 if it is to initialize the ctx.
+ *                             Set 1 if ctx is initialized and only to update
+ *                             session context data.
+ * @return
+ *   - On success return 0.
+ *   - On failure return negative integer.
+ */
+typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
+       struct rte_cryptodev *dev, uint16_t qp_id,
+       struct rte_crypto_raw_dp_ctx *ctx,
+       enum rte_crypto_op_sess_type sess_type,
+       union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
 
 /** Crypto device operations function pointer table */
 struct rte_cryptodev_ops {
@@ -322,19 +372,32 @@ struct rte_cryptodev_ops {
        /**< Set up a device queue pair. */
        cryptodev_queue_pair_release_t queue_pair_release;
        /**< Release a queue pair. */
-       cryptodev_queue_pair_count_t queue_pair_count;
-       /**< Get count of the queue pairs. */
 
-       cryptodev_sym_get_session_private_size_t session_get_size;
+       cryptodev_sym_get_session_private_size_t sym_session_get_size;
        /**< Return private session. */
-       cryptodev_sym_configure_session_t session_configure;
+       cryptodev_asym_get_session_private_size_t asym_session_get_size;
+       /**< Return asym session private size. */
+       cryptodev_sym_configure_session_t sym_session_configure;
        /**< Configure a Crypto session. */
-       cryptodev_sym_free_session_t session_clear;
+       cryptodev_asym_configure_session_t asym_session_configure;
+       /**< Configure asymmetric Crypto session. */
+       cryptodev_sym_free_session_t sym_session_clear;
        /**< Clear a Crypto sessions private data. */
-       cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
-       /**< Attach session to queue pair. */
-       cryptodev_sym_queue_pair_detach_session_t qp_detach_session;
-       /**< Detach session from queue pair. */
+       cryptodev_asym_free_session_t asym_session_clear;
+       /**< Clear a Crypto sessions private data. */
+       union {
+               cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
+               /**< process input data synchronously (cpu-crypto). */
+               __extension__
+               struct {
+                       cryptodev_sym_get_raw_dp_ctx_size_t
+                               sym_get_raw_dp_ctx_size;
+                       /**< Get raw data path service context data size. */
+                       cryptodev_sym_configure_raw_dp_ctx_t
+                               sym_configure_raw_dp_ctx;
+                       /**< Initialize raw data path context data. */
+               };
+       };
 };
 
 
@@ -459,20 +522,41 @@ uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
 
 
 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
-RTE_INIT(init_ ##driver_id);\
-static void init_ ##driver_id(void)\
+RTE_INIT(init_ ##driver_id)\
 {\
        driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
 }
 
 static inline void *
-get_session_private_data(const struct rte_cryptodev_sym_session *sess,
+get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
+               uint8_t driver_id) {
+       if (unlikely(sess->nb_drivers <= driver_id))
+               return NULL;
+
+       return sess->sess_data[driver_id].data;
+}
+
+static inline void
+set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
+               uint8_t driver_id, void *private_data)
+{
+       if (unlikely(sess->nb_drivers <= driver_id)) {
+               CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
+                               driver_id);
+               return;
+       }
+
+       sess->sess_data[driver_id].data = private_data;
+}
+
+static inline void *
+get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
                uint8_t driver_id) {
        return sess->sess_private_data[driver_id];
 }
 
 static inline void
-set_session_private_data(struct rte_cryptodev_sym_session *sess,
+set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
                uint8_t driver_id, void *private_data)
 {
        sess->sess_private_data[driver_id] = private_data;