From patchwork Fri Oct 28 08:33:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9401613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A9B93601C0 for ; Fri, 28 Oct 2016 08:51:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF6F2A08B for ; Fri, 28 Oct 2016 08:51:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 911752A189; Fri, 28 Oct 2016 08:51:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1ED92A08B for ; Fri, 28 Oct 2016 08:51:42 +0000 (UTC) Received: from localhost ([::1]:47534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c02t4-0007Tp-5G for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Oct 2016 04:51:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c02dD-00032n-PH for qemu-devel@nongnu.org; Fri, 28 Oct 2016 04:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c02dB-0005QM-5v for qemu-devel@nongnu.org; Fri, 28 Oct 2016 04:35:19 -0400 Received: from [119.145.14.65] (port=41485 helo=szxga02-in.huawei.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c02dA-0005KM-JR for qemu-devel@nongnu.org; Fri, 28 Oct 2016 04:35:17 -0400 Received: from 172.24.1.47 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DPT56487; Fri, 28 Oct 2016 16:33:57 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Fri, 28 Oct 2016 16:33:46 +0800 From: Gonglei To: , Date: Fri, 28 Oct 2016 16:33:29 +0800 Message-ID: <1477643611-78548-11-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.8.2.windows.1 In-Reply-To: <1477643611-78548-1-git-send-email-arei.gonglei@huawei.com> References: <1477643611-78548-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH v10 10/12] cryptodev: introduce an unified wrapper for crypto operation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xuquan8@huawei.com, weidong.huang@huawei.com, claudio.fontana@huawei.com, mst@redhat.com, xin.zeng@intel.com, hanweidong@huawei.com, luonengjun@huawei.com, agraf@suse.de, nmorey@kalray.eu, mike.caraman@nxp.com, Gonglei , stefanha@redhat.com, jianjay.zhou@huawei.com, pbonzini@redhat.com, peter.huangpeng@huawei.com, vincent.jardin@6wind.com, wu.wubin@huawei.com, arei.gonglei@hotmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We use an opaque point to the VirtIOCryptoReq which can support different packets based on different algorithms. Signed-off-by: Gonglei --- backends/cryptodev.c | 28 ++++++++++++++++++++++++++-- hw/virtio/virtio-crypto.c | 10 +++++----- include/sysemu/cryptodev.h | 13 +++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) 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 6c8770a..6faacb7 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -634,15 +634,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 e66bd4b..84526c0 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -278,20 +278,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 */