From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWVY-0003ei-9O for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWVR-0000wd-RV for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:04:28 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:64541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWVR-0000ve-7f for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:04:21 -0400 From: Gonglei Date: Mon, 10 Oct 2016 16:55:28 +0800 Message-ID: <1476089730-65776-11-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1476089730-65776-1-git-send-email-arei.gonglei@huawei.com> References: <1476089730-65776-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH RESEND v6 10/12] cryptodev: introduce an unified wrapper for crypto operation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: luonengjun@huawei.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, berrange@redhat.com, weidong.huang@huawei.com, wu.wubin@huawei.com, mike.caraman@nxp.com, agraf@suse.de, xin.zeng@intel.com, claudio.fontana@huawei.com, nmorey@kalray.eu, vincent.jardin@6wind.com, jianjay.zhou@huawei.com, hanweidong@huawei.com, peter.huangpeng@huawei.com, arei.gonglei@hotmail.com, eblake@redhat.com, Gonglei We use an opaque point to the VirtIOCryptoReq which can support different packets based on different algorithms. Signed-off-by: Gonglei --- backends/cryptodev-builtin.c | 2 +- backends/cryptodev.c | 28 ++++++++++++++++++++++++++-- hw/virtio/virtio-crypto.c | 10 +++++----- include/sysemu/cryptodev.h | 13 +++++++------ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 34c45be..dc0a364 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -286,7 +286,7 @@ static int cryptodev_builtin_sym_operation( return -VIRTIO_CRYPTO_ERR; } } - return 0; + return VIRTIO_CRYPTO_OK; } static void cryptodev_builtin_cleanup( diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 47521cf..4a49f97 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 diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 29eb1a1..1729579 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -600,15 +600,15 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) /* Set request's parameter */ request->flags = CRYPTODEV_BACKEND_ALG_SYM; request->u.sym_op_info = sym_op_info; - ret = cryptodev_backend_sym_operation(vcrypto->cryptodev, - sym_op_info, queue_index, &local_err); + ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev, + request, queue_index, &local_err); if (ret < 0) { - status = VIRTIO_CRYPTO_ERR; + status = -ret; if (local_err) { error_report_err(local_err); } - } else { /* ret >= 0 */ - status = VIRTIO_CRYPTO_OK; + } else { /* ret == VIRTIO_CRYPTO_OK */ + status = ret; } virtio_crypto_req_complete(request, status); virtio_crypto_free_request(request); diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 8fbf1e2..f55b79e 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -264,20 +264,21 @@ int cryptodev_backend_sym_close_session( uint32_t queue_index, Error **errp); /** - * cryptodev_backend_sym_operation: + * cryptodev_backend_crypto_operation: * @backend: the cryptodev backend object - * @op_info: parameters needed by symmetric crypto operation + * @opaque: pointer to a VirtIOCryptoReq object * @queue_index: queue index of cryptodev backend client * @errp: pointer to a NULL-initialized error object * - * Do symmetric crypto operation, such as encryption and + * Do crypto operation, such as encryption and * decryption * - * Returns: 0 on success, or Negative on error + * Returns: VIRTIO_CRYPTO_OK on success, + * or -VIRTIO_CRYPTO_* on error */ -int cryptodev_backend_sym_operation( +int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - CryptoDevBackendSymOpInfo *op_info, + void *opaque, uint32_t queue_index, Error **errp); #endif /* CRYPTODEV_H */ -- 1.7.12.4