net/virtio: rationalize queue flushing
[dpdk.git] / lib / librte_cryptodev / rte_cryptodev_pmd.h
index 82ad1f7..089848e 100644 (file)
@@ -46,6 +46,7 @@ extern "C" {
 
 #include <string.h>
 
+#include <rte_config.h>
 #include <rte_dev.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
@@ -56,6 +57,35 @@ extern "C" {
 #include "rte_crypto.h"
 #include "rte_cryptodev.h"
 
+
+#define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS   8
+#define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS      2048
+
+#define RTE_CRYPTODEV_PMD_NAME_ARG                     ("name")
+#define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG                        ("max_nb_queue_pairs")
+#define RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG              ("max_nb_sessions")
+#define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG                        ("socket_id")
+
+
+static const char * const cryptodev_pmd_valid_params[] = {
+       RTE_CRYPTODEV_PMD_NAME_ARG,
+       RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
+       RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG,
+       RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
+};
+
+/**
+ * @internal
+ * Initialisation parameters for crypto devices
+ */
+struct rte_cryptodev_pmd_init_params {
+       char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+       size_t private_data_size;
+       int socket_id;
+       unsigned int max_nb_queue_pairs;
+       unsigned int max_nb_sessions;
+};
+
 /** Global structure used for maintaining state of allocated crypto devices */
 struct rte_cryptodev_global {
        struct rte_cryptodev *devs;     /**< Device information array */
@@ -65,6 +95,13 @@ struct rte_cryptodev_global {
        uint8_t max_devs;               /**< Max number of devices */
 };
 
+/* Cryptodev driver, containing the driver ID */
+struct cryptodev_driver {
+       TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
+       const struct rte_driver *driver;
+       uint8_t id;
+};
+
 /** pointer to global crypto devices data structure. */
 extern struct rte_cryptodev_global *rte_cryptodev_globals;
 
@@ -266,20 +303,6 @@ typedef int (*cryptodev_sym_create_session_pool_t)(
 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
                struct rte_cryptodev *dev);
 
-/**
- * Initialize a Crypto 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
- *
- * @return
- *  - Returns private session structure on success.
- *  - Returns NULL on failure.
- */
-typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
-               void *session_private);
-
 /**
  * Configure a Crypto session on a device.
  *
@@ -290,7 +313,9 @@ typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
  *
  * @return
  *  - Returns 0 if private session structure have been created successfully.
- *  - Returns -1 on failure.
+ *  - 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_sym_configure_session_t)(struct rte_cryptodev *dev,
                struct rte_crypto_sym_xform *xform,
@@ -359,15 +384,13 @@ struct rte_cryptodev_ops {
 
        cryptodev_sym_get_session_private_size_t session_get_size;
        /**< Return private session. */
-       cryptodev_sym_initialize_session_t session_initialize;
-       /**< Initialization function for private session data */
        cryptodev_sym_configure_session_t session_configure;
        /**< Configure a Crypto session. */
        cryptodev_sym_free_session_t 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_attach_session_t qp_detach_session;
+       cryptodev_sym_queue_pair_detach_session_t qp_detach_session;
        /**< Detach session from queue pair. */
 };
 
@@ -399,6 +422,63 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id);
 extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
+
+/**
+ * @internal
+ *
+ * PMD assist function to parse initialisation arguments for crypto driver
+ * when creating a new crypto PMD device instance.
+ *
+ * PMD driver should set default values for that PMD before calling function,
+ * these default values will be over-written with successfully parsed values
+ * from args string.
+ *
+ * @param      params  parsed PMD initialisation parameters
+ * @param      args    input argument string to parse
+ *
+ * @return
+ *  - 0 on success
+ *  - errno on failure
+ */
+int
+rte_cryptodev_pmd_parse_input_args(
+               struct rte_cryptodev_pmd_init_params *params,
+               const char *args);
+
+/**
+ * @internal
+ *
+ * PMD assist function to provide boiler plate code for crypto driver to create
+ * and allocate resources for a new crypto PMD device instance.
+ *
+ * @param      name    crypto device name.
+ * @param      device  base device instance
+ * @param      params  PMD initialisation parameters
+ *
+ * @return
+ *  - crypto device instance on success
+ *  - NULL on creation failure
+ */
+struct rte_cryptodev *
+rte_cryptodev_pmd_create(const char *name,
+               struct rte_device *device,
+               struct rte_cryptodev_pmd_init_params *params);
+
+/**
+ * @internal
+ *
+ * PMD assist function to provide boiler plate code for crypto driver to
+ * destroy and free resources associated with a crypto PMD device instance.
+ *
+ * @param      cryptodev       crypto device handle.
+ *
+ * @return
+ *  - 0 on success
+ *  - errno on failure
+ */
+int
+rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
+
 /**
  * Executes all the user application registered callbacks for the specific
  * device.
@@ -419,6 +499,29 @@ void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 int
 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
 
+/**
+ * @internal
+ * Allocate Cryptodev driver.
+ *
+ * @param crypto_drv
+ *   Pointer to cryptodev_driver.
+ * @param drv
+ *   Pointer to rte_driver.
+ *
+ * @return
+ *  The driver type identifier
+ */
+uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
+               const struct rte_driver *drv);
+
+
+#define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
+RTE_INIT(init_ ##driver_id);\
+static void init_ ##driver_id(void)\
+{\
+       driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv).driver);\
+}
+
 static inline void *
 get_session_private_data(const struct rte_cryptodev_sym_session *sess,
                uint8_t driver_id) {