summary refs log tree commit diff stats
path: root/backends/cryptodev.c
diff options
context:
space:
mode:
authorGonglei <arei.gonglei@huawei.com>2016-10-28 16:33:29 +0800
committerMichael S. Tsirkin <mst@redhat.com>2016-11-01 19:21:08 +0200
commitd6634ac09abf20d890fd094773f125ee0ff0b1cb (patch)
tree1d7a92f2a248141b8404d5a7eaf67c1c40ea9f6c /backends/cryptodev.c
parent04b9b37edda85964cca033a48dcc0298036782f2 (diff)
downloadfocaccia-qemu-d6634ac09abf20d890fd094773f125ee0ff0b1cb.tar.gz
focaccia-qemu-d6634ac09abf20d890fd094773f125ee0ff0b1cb.zip
cryptodev: introduce an unified wrapper for crypto operation
We use an opaque point to the VirtIOCryptoReq which
can support different packets based on different
algorithms.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'backends/cryptodev.c')
-rw-r--r--backends/cryptodev.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 47521cf963..4a49f9762f 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -30,6 +30,8 @@
 #include "qapi-visit.h"
 #include "qemu/config-file.h"
 #include "qom/object_interfaces.h"
+#include "hw/virtio/virtio-crypto.h"
+
 
 static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients;
 
@@ -105,7 +107,7 @@ int cryptodev_backend_sym_close_session(
     return -1;
 }
 
-int cryptodev_backend_sym_operation(
+static int cryptodev_backend_sym_operation(
                  CryptoDevBackend *backend,
                  CryptoDevBackendSymOpInfo *op_info,
                  uint32_t queue_index, Error **errp)
@@ -117,7 +119,29 @@ int cryptodev_backend_sym_operation(
         return bc->do_sym_op(backend, op_info, queue_index, errp);
     }
 
-    return -1;
+    return -VIRTIO_CRYPTO_ERR;
+}
+
+int cryptodev_backend_crypto_operation(
+                 CryptoDevBackend *backend,
+                 void *opaque,
+                 uint32_t queue_index, Error **errp)
+{
+    VirtIOCryptoReq *req = opaque;
+
+    if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
+        CryptoDevBackendSymOpInfo *op_info;
+        op_info = req->u.sym_op_info;
+
+        return cryptodev_backend_sym_operation(backend,
+                         op_info, queue_index, errp);
+    } else {
+        error_setg(errp, "Unsupported cryptodev alg type: %" PRIu32 "",
+                   req->flags);
+       return -VIRTIO_CRYPTO_NOTSUPP;
+    }
+
+    return -VIRTIO_CRYPTO_ERR;
 }
 
 static void