crypto: support scatter-gather in software drivers
[dpdk.git] / drivers / crypto / snow3g / rte_snow3g_pmd.c
index dc8de6b..9a6f16d 100644 (file)
@@ -35,7 +35,7 @@
 #include <rte_hexdump.h>
 #include <rte_cryptodev.h>
 #include <rte_cryptodev_pmd.h>
-#include <rte_dev.h>
+#include <rte_vdev.h>
 #include <rte_malloc.h>
 #include <rte_cpuflags.h>
 
@@ -60,7 +60,7 @@ create_unique_device_name(char *name, size_t size)
        if (name == NULL)
                return -EINVAL;
 
-       ret = snprintf(name, size, "%s_%u", CRYPTODEV_NAME_SNOW3G_PMD,
+       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD),
                        unique_name_id++);
        if (ret < 0)
                return ret;
@@ -107,7 +107,7 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
 {
        const struct rte_crypto_sym_xform *auth_xform = NULL;
        const struct rte_crypto_sym_xform *cipher_xform = NULL;
-       int mode;
+       enum snow3g_operation mode;
 
        /* Select Crypto operation - hash then cipher / cipher then hash */
        mode = snow3g_get_mode(xform);
@@ -125,9 +125,9 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
                /* Fall-through */
        case SNOW3G_OP_ONLY_AUTH:
                auth_xform = xform;
-       }
-
-       if (mode == SNOW3G_OP_NOT_SUPPORTED) {
+               break;
+       case SNOW3G_OP_NOT_SUPPORTED:
+       default:
                SNOW3G_LOG_ERR("Unsupported operation chain order parameter");
                return -EINVAL;
        }
@@ -330,6 +330,21 @@ process_ops(struct rte_crypto_op **ops, struct snow3g_session *session,
        unsigned i;
        unsigned enqueued_ops, processed_ops;
 
+#ifdef RTE_LIBRTE_PMD_SNOW3G_DEBUG
+       for (i = 0; i < num_ops; i++) {
+               if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
+                               (ops[i]->sym->m_dst != NULL &&
+                               !rte_pktmbuf_is_contiguous(
+                                               ops[i]->sym->m_dst))) {
+                       SNOW3G_LOG_ERR("PMD supports only contiguous mbufs, "
+                               "op (%p) provides noncontiguous mbuf as "
+                               "source/destination buffer.\n", ops[i]);
+                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+                       return 0;
+               }
+       }
+#endif
+
        switch (session->op) {
        case SNOW3G_OP_ONLY_CIPHER:
                processed_ops = process_snow3g_cipher_op(ops,
@@ -545,7 +560,7 @@ snow3g_pmd_dequeue_burst(void *queue_pair,
        return nb_dequeued;
 }
 
-static int cryptodev_snow3g_uninit(const char *name);
+static int cryptodev_snow3g_remove(const char *name);
 
 static int
 cryptodev_snow3g_create(const char *name,
@@ -599,12 +614,12 @@ cryptodev_snow3g_create(const char *name,
 init_error:
        SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed", name);
 
-       cryptodev_snow3g_uninit(crypto_dev_name);
+       cryptodev_snow3g_remove(crypto_dev_name);
        return -EFAULT;
 }
 
 static int
-cryptodev_snow3g_init(const char *name,
+cryptodev_snow3g_probe(const char *name,
                const char *input_args)
 {
        struct rte_crypto_vdev_init_params init_params = {
@@ -626,23 +641,26 @@ cryptodev_snow3g_init(const char *name,
 }
 
 static int
-cryptodev_snow3g_uninit(const char *name)
+cryptodev_snow3g_remove(const char *name)
 {
        if (name == NULL)
                return -EINVAL;
 
-       RTE_LOG(INFO, PMD, "Closing SNOW3G crypto device %s"
+       RTE_LOG(INFO, PMD, "Closing SNOW 3G crypto device %s"
                        " on numa socket %u\n",
                        name, rte_socket_id());
 
        return 0;
 }
 
-static struct rte_driver cryptodev_snow3g_pmd_drv = {
-       .name = CRYPTODEV_NAME_SNOW3G_PMD,
-       .type = PMD_VDEV,
-       .init = cryptodev_snow3g_init,
-       .uninit = cryptodev_snow3g_uninit
+static struct rte_vdev_driver cryptodev_snow3g_pmd_drv = {
+       .probe = cryptodev_snow3g_probe,
+       .remove = cryptodev_snow3g_remove
 };
 
-PMD_REGISTER_DRIVER(cryptodev_snow3g_pmd_drv);
+RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd_drv);
+RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd);
+RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
+       "max_nb_queue_pairs=<int> "
+       "max_nb_sessions=<int> "
+       "socket_id=<int>");